136 lines
6.1 KiB
YAML
136 lines
6.1 KiB
YAML
-
|
|
I create a draft Purchase Order
|
|
-
|
|
!record {model: purchase.order, id: purchase_order_edi_1}:
|
|
partner_id: base.res_partner_3
|
|
location_id: stock.stock_location_3
|
|
pricelist_id: 1
|
|
order_line:
|
|
- product_id: product.product_product_33
|
|
product_qty: 10.0
|
|
product_uom: 1
|
|
price_unit: 60.0
|
|
name: 'Headset USB'
|
|
date_planned: '2011-08-31'
|
|
order_line:
|
|
- product_id: product.product_product_29
|
|
product_qty: 12.0
|
|
product_uom: 1
|
|
price_unit: 89.0
|
|
name: 'Pen drive, 8GB'
|
|
date_planned: '2011-08-31'
|
|
|
|
-
|
|
I confirm the purchase order
|
|
-
|
|
!workflow {model: purchase.order, ref: purchase_order_edi_1, action: purchase_confirm}
|
|
-
|
|
Then I export the purchase order via EDI
|
|
-
|
|
!python {model: edi.edi}: |
|
|
import json
|
|
order_pool = self.pool.get('purchase.order')
|
|
order = order_pool.browse(cr, uid, ref("purchase_order_edi_1"))
|
|
edi_doc = self.generate_edi(cr, uid, [order])
|
|
assert isinstance(json.loads(edi_doc)[0], dict), 'EDI doc should be a JSON dict'
|
|
-
|
|
Then I import a sample EDI document of a sale order
|
|
-
|
|
!python {model: edi.edi}: |
|
|
purchase_order_pool = self.pool.get('purchase.order')
|
|
edi_document = {
|
|
"__id": "sale:724f93ec-ddd0-11e0-88ec-701a04e25543.sale_order_test",
|
|
"__module": "sale",
|
|
"__model": "sale.order",
|
|
"__import_module": "purchase",
|
|
"__import_model": "purchase.order",
|
|
"__version": [6,1,0],
|
|
"name": "SO008",
|
|
"currency": {
|
|
"__id": "base:724f93ec-ddd0-11e0-88ec-701a04e25543.EUR",
|
|
"__module": "base",
|
|
"__model": "res.currency",
|
|
"code": "EUR",
|
|
"symbol": "€",
|
|
},
|
|
"date_order": "2011-09-13",
|
|
"partner_id": ["sale:724f93ec-ddd0-11e0-88ec-701a04e25543.res_partner_test22", "Junjun wala"],
|
|
"partner_address": {
|
|
"__id": "base:724f93ec-ddd0-11e0-88ec-701a04e25543.res_partner_address_7wdsjasdjh",
|
|
"__module": "base",
|
|
"__model": "res.partner",
|
|
"phone": "(+32).81.81.37.00",
|
|
"street": "Chaussee de Namur 40",
|
|
"city": "Gerompont",
|
|
"zip": "1367",
|
|
"country_id": ["base:5af1272e-dd26-11e0-b65e-701a04e25543.be", "Belgium"],
|
|
},
|
|
"company_id": ["base:724f93ec-ddd0-11e0-88ec-701a04e25543.main_company", "Supplier S.A."],
|
|
"company_address": {
|
|
"__id": "base:724f93ec-ddd0-11e0-88ec-701a04e25543.main_address",
|
|
"__module": "base",
|
|
"__model": "res.partner",
|
|
"city": "Gerompont",
|
|
"zip": "1367",
|
|
"country_id": ["base:724f93ec-ddd0-11e0-88ec-701a04e25543.be", "Belgium"],
|
|
"phone": "(+32).81.81.37.00",
|
|
"street": "Chaussee de Namur 40",
|
|
"street2": "mailbox 34",
|
|
"bank_ids": [
|
|
["base:724f93ec-ddd0-11e0-88ec-701a04e25543.res_partner_bank-XiwqnxKWzGbp","Guys bank: 123477777-156113"]
|
|
],
|
|
},
|
|
"order_line": [{
|
|
"__id": "sale:724f93ec-ddd0-11e0-88ec-701a04e25543.sale_order_line-LXEqeuI-SSP0",
|
|
"__module": "sale",
|
|
"__model": "sale.order.line",
|
|
"__import_module": "purchase",
|
|
"__import_model": "purchase.order.line",
|
|
"name": "PC Assemble SC234",
|
|
"product_uom": ["product:724f93ec-ddd0-11e0-88ec-701a04e25543.product_uom_unit", "Unit"],
|
|
"product_qty": 1.0,
|
|
"date_planned": "2011-09-30",
|
|
"sequence": 10,
|
|
"price_unit": 150.0,
|
|
"product_id": ["product:724f93ec-ddd0-11e0-88ec-701a04e25543.product_product_3", "[PCSC234] PC Assemble SC234"],
|
|
},
|
|
{
|
|
"__id": "sale:724f93ec-ddd0-11e0-88ec-701a04e25543.sale_order_line-LXEqeadasdad",
|
|
"__module": "sale",
|
|
"__model": "sale.order.line",
|
|
"__import_module": "purchase",
|
|
"__import_model": "purchase.order.line",
|
|
"name": "PC on Demand",
|
|
"product_uom": ["product:724f93ec-ddd0-11e0-88ec-701a04e25543.product_uom_unit", "Unit"],
|
|
"product_qty": 10.0,
|
|
"sequence": 11,
|
|
"date_planned": "2011-09-15",
|
|
"price_unit": 20.0,
|
|
"product_id": ["product:724f93ec-ddd0-11e0-88ec-701a04e25543.product_product_5", "[PC-DEM] PC on Demand"],
|
|
}],
|
|
}
|
|
new_purchase_order_id = purchase_order_pool.edi_import(cr, uid, edi_document, context=context)
|
|
assert new_purchase_order_id, 'Purchase order import failed'
|
|
order_new = purchase_order_pool.browse(cr, uid, new_purchase_order_id)
|
|
|
|
# check bank info on partner
|
|
assert len(order_new.partner_id.bank_ids) == 1, "Expected 1 bank entry related to partner"
|
|
bank_info = order_new.partner_id.bank_ids[0]
|
|
assert bank_info.acc_number == "Guys bank: 123477777-156113", 'Expected "Guys bank: 123477777-156113", got %s' % bank_info.acc_number
|
|
|
|
assert order_new.pricelist_id.name == 'Default Purchase Pricelist' , "Default Purchase Pricelist was not automatically assigned"
|
|
assert order_new.amount_total == 350, "Amount total is not same"
|
|
assert order_new.amount_untaxed == 350, "untaxed amount is not same"
|
|
assert len(order_new.order_line) == 2, "Purchase order lines number mismatch"
|
|
for purchase_line in order_new.order_line:
|
|
if purchase_line.name == 'PC Assemble SC234':
|
|
assert purchase_line.product_uom.name == "Unit" , "uom is not same"
|
|
assert purchase_line.price_unit == 150 , "unit price is not same, got %s, expected 150"%(purchase_line.price_unit,)
|
|
assert purchase_line.product_qty == 1 , "product qty is not same"
|
|
elif purchase_line.name == 'PC on Demand':
|
|
assert purchase_line.product_uom.name == "Unit" , "uom is not same"
|
|
assert purchase_line.price_unit == 20 , "unit price is not same, got %s, expected 20"%(purchase_line.price_unit,)
|
|
assert purchase_line.product_qty == 10 , "product qty is not same"
|
|
else:
|
|
raise AssertionError('unknown order line: %s' % purchase_line)
|