From 8cfb45d5504376a9ade6e486af0375140a7d91c8 Mon Sep 17 00:00:00 2001 From: "Kirti Savalia (OpenERP)" Date: Wed, 30 Nov 2011 16:13:34 +0530 Subject: [PATCH 01/10] [ADD]:demo data for the product with account information bzr revid: ksa@tinyerp.com-20111130104334-h7zjiuvq922n43nq --- addons/purchase/purchase_demo.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/addons/purchase/purchase_demo.xml b/addons/purchase/purchase_demo.xml index 6999f85b076..406e8d89abc 100644 --- a/addons/purchase/purchase_demo.xml +++ b/addons/purchase/purchase_demo.xml @@ -14,6 +14,13 @@ + + + + + + + From 8029e57b00f9a2fddfec3f9034dc36e1930fbc6b Mon Sep 17 00:00:00 2001 From: "Kirti Savalia (OpenERP)" Date: Wed, 30 Nov 2011 16:16:18 +0530 Subject: [PATCH 02/10] [ADD]:yml for stock real time accounting valuation bzr revid: ksa@tinyerp.com-20111130104618-r3p550bnov9wjjhf --- addons/purchase/__openerp__.py | 1 + .../test/process/real_time_valuation.yml | 42 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 addons/purchase/test/process/real_time_valuation.yml diff --git a/addons/purchase/__openerp__.py b/addons/purchase/__openerp__.py index b4f3a9adf30..68e490d23f1 100644 --- a/addons/purchase/__openerp__.py +++ b/addons/purchase/__openerp__.py @@ -67,6 +67,7 @@ Dashboard for purchase management that includes: 'test/process/run_scheduler.yml', 'test/process/merge_order.yml', 'test/process/edi_purchase_order.yml', + 'test/process/real_time_valuation.yml', 'test/ui/print_report.yml', 'test/ui/duplicate_order.yml', 'test/ui/delete_order.yml', diff --git a/addons/purchase/test/process/real_time_valuation.yml b/addons/purchase/test/process/real_time_valuation.yml new file mode 100644 index 00000000000..d1b4cb267f1 --- /dev/null +++ b/addons/purchase/test/process/real_time_valuation.yml @@ -0,0 +1,42 @@ +- + In order to test real time stock valuation flow,I start by creating a new product 'Sugar' +- + !record {model: product.product, id: product_sugar_id_50kg}: + name: Sugar + procure_method: make_to_stock + supply_method: buy + cost_method: standard + standard_price: 3600.0 + uom_id: product.product_uom_kgm + uom_po_id: product.product_uom_gram + valuation: real_time + categ_id: product.product_category_rawmaterial0 +- + I create a draft Purchase Order +- + !record {model: purchase.order, id: purchase_order_sugar}: + partner_id: base.res_partner_agrolait + partner_address_id: base.res_partner_address_8invoice + pricelist_id: 1 + order_line: + - product_id: product_sugar_id_50kg + product_qty: 1.0 + product_uom: product.product_uom_gram + price_unit: 3600000 + name: 'Sugar' + date_planned: '2011-08-31' +- + I confirm the purchase order +- + !workflow {model: purchase.order, ref: purchase_order_sugar, action: purchase_confirm} +- + I check that the invoice of order and values. +- + !python {model: purchase.order}: | + purchase_order = self.browse(cr, uid, ref("purchase_order_sugar")) + for purchase_line in purchase_order.order_line: + assert purchase_line.price_unit == 3600000.0 + assert len(purchase_order.invoice_ids) == 1, "Invoice should be generated." + for invoice_line in purchase_order.invoice_ids: + for data in invoice_line.invoice_line: + assert data.price_unit == 3600000.0, "unit price is not same, got %s, expected 3600000.0"%(purchase_line.price_unit,) From 296622e5f755ed7bab5f44a7825e80bbe6c9ed0d Mon Sep 17 00:00:00 2001 From: "Kirti Savalia (OpenERP)" Date: Mon, 5 Dec 2011 16:13:22 +0530 Subject: [PATCH 03/10] [ADD]: demo data for different uom bzr revid: ksa@tinyerp.com-20111205104322-f63d4ujlt64kl0p1 --- addons/product/product_demo.xml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/addons/product/product_demo.xml b/addons/product/product_demo.xml index 3aebec13715..a95b41e546c 100644 --- a/addons/product/product_demo.xml +++ b/addons/product/product_demo.xml @@ -636,6 +636,20 @@ + + SUGAR50KG + buy + + 110.0 + 3600.0 + + + SUGAR of 50KG + + product + + + @@ -777,6 +791,15 @@ 5 + + + 10 + 1 + 5 + + 5 + + From 8af8d336375d6f0ddc4e278b9bfddb695713cccd Mon Sep 17 00:00:00 2001 From: "Kirti Savalia (OpenERP)" Date: Mon, 5 Dec 2011 16:14:59 +0530 Subject: [PATCH 04/10] [IMP]:code for product onchange when uom is different bzr revid: ksa@tinyerp.com-20111205104459-p2hnekd0tazuia2n --- addons/purchase/purchase.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 0dc015834a0..cea5aeeef4f 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -727,10 +727,12 @@ class purchase_order_line(osv.osv): # - name of method should "onchange_product_id" # - docstring # - merge 'product_uom_change' method - # - split into small internal methods for clearity + # - split into small internal methods for clearity def product_id_change(self, cr, uid, ids, pricelist, product, qty, uom, partner_id, date_order=False, fiscal_position=False, date_planned=False, - name=False, price_unit=False, notes=False, context={}): + name=False, price_unit=False, notes=False, context=None): + if context is None: + context = {} if not pricelist: raise osv.except_osv(_('No Pricelist !'), _('You have to select a pricelist or a supplier in the purchase form !\nPlease set one before choosing a product.')) if not partner_id: @@ -744,11 +746,14 @@ class purchase_order_line(osv.osv): lang=False if partner_id: lang=self.pool.get('res.partner').read(cr, uid, partner_id, ['lang'])['lang'] - context={'lang':lang} + context['lang'] = lang context['partner_id'] = partner_id prod = self.pool.get('product.product').browse(cr, uid, product, context=context) prod_uom_po = prod.uom_po_id.id + + if uom and prod and (uom <> prod_uom_po): + uom = prod_uom_po if not uom: uom = prod_uom_po if not date_order: @@ -773,6 +778,7 @@ class purchase_order_line(osv.osv): if qty < temp_qty: # If the supplier quantity is greater than entered from user, set minimal. qty = temp_qty res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s, you should not purchase less.') % qty}}) + uom = context.get('uom_change', uom) qty_in_product_uom = product_uom_pool._compute_qty(cr, uid, uom, qty, to_uom_id=prod.uom_id.id) price = self.pool.get('product.pricelist').price_get(cr,uid,[pricelist], product, qty_in_product_uom or 1.0, partner_id, { @@ -786,7 +792,7 @@ class purchase_order_line(osv.osv): 'taxes_id':map(lambda x: x.id, prod.supplier_taxes_id), 'date_planned': date_planned or dt,'notes': notes or prod.description_purchase, 'product_qty': qty, - 'product_uom': prod.uom_id.id}}) + 'product_uom': uom or prod_uom_po}}) domain = {} taxes = self.pool.get('account.tax').browse(cr, uid,map(lambda x: x.id, prod.supplier_taxes_id)) @@ -808,7 +814,7 @@ class purchase_order_line(osv.osv): name=False, price_unit=False, notes=False, context={}): res = self.product_id_change(cr, uid, ids, pricelist, product, qty, uom, partner_id, date_order=date_order, fiscal_position=fiscal_position, date_planned=date_planned, - name=name, price_unit=price_unit, notes=notes, context=context) + name=name, price_unit=price_unit, notes=notes, context={'uom_change': uom}) if 'product_uom' in res['value']: if uom and (uom != res['value']['product_uom']) and res['value']['product_uom']: seller_uom_name = self.pool.get('product.uom').read(cr, uid, [res['value']['product_uom']], ['name'])[0]['name'] From 6709a80bbcb8f7f2fe3dccd528cd7743c54182d9 Mon Sep 17 00:00:00 2001 From: "Kirti Savalia (OpenERP)" Date: Mon, 5 Dec 2011 16:15:41 +0530 Subject: [PATCH 05/10] [IMP]:yml for real time valuation value bzr revid: ksa@tinyerp.com-20111205104541-suka3mhly9ry8xdc --- addons/purchase/purchase_order_demo.yml | 5 +++ .../test/process/real_time_valuation.yml | 42 ++----------------- 2 files changed, 9 insertions(+), 38 deletions(-) diff --git a/addons/purchase/purchase_order_demo.yml b/addons/purchase/purchase_order_demo.yml index abfaa102033..8cd9271de45 100644 --- a/addons/purchase/purchase_order_demo.yml +++ b/addons/purchase/purchase_order_demo.yml @@ -74,3 +74,8 @@ - product_id: product.product_product_1 product_qty: 15 +- + !record {model: purchase.order, id: order_purchase8}: + partner_id: base.res_partner_asus + order_line: + - product_id: product.product_sugar_id_50kg diff --git a/addons/purchase/test/process/real_time_valuation.yml b/addons/purchase/test/process/real_time_valuation.yml index d1b4cb267f1..69b04071f40 100644 --- a/addons/purchase/test/process/real_time_valuation.yml +++ b/addons/purchase/test/process/real_time_valuation.yml @@ -1,42 +1,8 @@ - - In order to test real time stock valuation flow,I start by creating a new product 'Sugar' -- - !record {model: product.product, id: product_sugar_id_50kg}: - name: Sugar - procure_method: make_to_stock - supply_method: buy - cost_method: standard - standard_price: 3600.0 - uom_id: product.product_uom_kgm - uom_po_id: product.product_uom_gram - valuation: real_time - categ_id: product.product_category_rawmaterial0 -- - I create a draft Purchase Order -- - !record {model: purchase.order, id: purchase_order_sugar}: - partner_id: base.res_partner_agrolait - partner_address_id: base.res_partner_address_8invoice - pricelist_id: 1 - order_line: - - product_id: product_sugar_id_50kg - product_qty: 1.0 - product_uom: product.product_uom_gram - price_unit: 3600000 - name: 'Sugar' - date_planned: '2011-08-31' -- - I confirm the purchase order -- - !workflow {model: purchase.order, ref: purchase_order_sugar, action: purchase_confirm} -- - I check that the invoice of order and values. + In order to test real time stock valuation flow, when default UoM and purchase UoM is different - !python {model: purchase.order}: | - purchase_order = self.browse(cr, uid, ref("purchase_order_sugar")) + purchase_order = self.browse(cr, uid, ref("order_purchase8")) + assert len(purchase_order.order_line) == 1, "orderline should be generated." for purchase_line in purchase_order.order_line: - assert purchase_line.price_unit == 3600000.0 - assert len(purchase_order.invoice_ids) == 1, "Invoice should be generated." - for invoice_line in purchase_order.invoice_ids: - for data in invoice_line.invoice_line: - assert data.price_unit == 3600000.0, "unit price is not same, got %s, expected 3600000.0"%(purchase_line.price_unit,) + assert purchase_line.price_unit == 3.6 ,"unit price is not same, got %s, expected 3.6"%(purchase_line.price_unit,) \ No newline at end of file From 31f3f8651031f4c4de3c16f6e90bf4d1f6619600 Mon Sep 17 00:00:00 2001 From: "Kirti Savalia (OpenERP)" Date: Thu, 8 Dec 2011 15:25:59 +0530 Subject: [PATCH 06/10] [IMP]:check the flow when default UoM and purchase UoM is different bzr revid: ksa@tinyerp.com-20111208095559-9qt47pftmtr55yh1 --- addons/product/product_demo.xml | 23 ----------- addons/purchase/purchase_demo.xml | 7 ---- addons/purchase/purchase_order_demo.yml | 19 ++++++++- .../test/process/real_time_valuation.yml | 39 ++++++++++++++++--- 4 files changed, 51 insertions(+), 37 deletions(-) diff --git a/addons/product/product_demo.xml b/addons/product/product_demo.xml index a95b41e546c..3aebec13715 100644 --- a/addons/product/product_demo.xml +++ b/addons/product/product_demo.xml @@ -636,20 +636,6 @@ - - SUGAR50KG - buy - - 110.0 - 3600.0 - - - SUGAR of 50KG - - product - - - @@ -791,15 +777,6 @@ 5 - - - 10 - 1 - 5 - - 5 - - diff --git a/addons/purchase/purchase_demo.xml b/addons/purchase/purchase_demo.xml index 406e8d89abc..6999f85b076 100644 --- a/addons/purchase/purchase_demo.xml +++ b/addons/purchase/purchase_demo.xml @@ -14,13 +14,6 @@ - - - - - - - diff --git a/addons/purchase/purchase_order_demo.yml b/addons/purchase/purchase_order_demo.yml index 8cd9271de45..0ea29b2a242 100644 --- a/addons/purchase/purchase_order_demo.yml +++ b/addons/purchase/purchase_order_demo.yml @@ -75,7 +75,22 @@ product_qty: 15 - - !record {model: purchase.order, id: order_purchase8}: + !record {model: product.product, id: product_sugar_id_50kg}: + default_code: SUGAR50KG + supply_method: buy + list_price: 110.0 + standard_price: 3600.0 + uom_id: product.product_uom_kgm + uom_po_id: product.product_uom_gram + name: SUGAR of 50KG + valuation: real_time + property_stock_account_input: account.o_expense + property_stock_account_output: account.o_income + categ_id: product.product_category_rawmaterial0 + +- + !record {model: purchase.order, id: order_purchase_sugar}: partner_id: base.res_partner_asus order_line: - - product_id: product.product_sugar_id_50kg + - product_id: product_sugar_id_50kg + diff --git a/addons/purchase/test/process/real_time_valuation.yml b/addons/purchase/test/process/real_time_valuation.yml index 69b04071f40..f0234888ba6 100644 --- a/addons/purchase/test/process/real_time_valuation.yml +++ b/addons/purchase/test/process/real_time_valuation.yml @@ -1,8 +1,37 @@ - - In order to test real time stock valuation flow, when default UoM and purchase UoM is different + In order to test real time stock valuation flow, I confirmed the purchase order. +- + !workflow {model: purchase.order, action: purchase_confirm, ref: order_purchase_sugar} +- + I check that the order which was initially in the draft state has transmit to approved state. +- + !assert {model: purchase.order, id: order_purchase_sugar}: + - state == 'approved' +- + In order to test check that picking is generated or not. - !python {model: purchase.order}: | - purchase_order = self.browse(cr, uid, ref("order_purchase8")) - assert len(purchase_order.order_line) == 1, "orderline should be generated." - for purchase_line in purchase_order.order_line: - assert purchase_line.price_unit == 3.6 ,"unit price is not same, got %s, expected 3.6"%(purchase_line.price_unit,) \ No newline at end of file + purchase_order = self.browse(cr, uid, ref("order_purchase_sugar")) + assert len(purchase_order.picking_ids) >= 1, "You should have only one reception order" + for picking in purchase_order.picking_ids: + assert picking.purchase_id.id == purchase_order.id +- + Reception is ready for process so now done the reception. +- + !python {model: stock.partial.picking}: | + pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("order_purchase_sugar")).picking_ids + partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]}) + self.do_partial(cr, uid, [partial_id]) +- + Check the Journal having proper amount or not. +- + !python {model: account.move.line}: | + pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("order_purchase_sugar")).picking_ids + for data in pick_ids: + for moveline in data.move_lines: + ids = self.pool.get('account.move.line').search(cr, uid, [('ref','=',data.name),('partner_id','=',data.partner_id.id)]) + item_data = self.pool.get('account.move.line').browse(cr, uid, ids) + for item in item_data: + if item.account_id.id == moveline.product_id.property_stock_account_input.id: + assert item.credit == 3.6, "Journal items have not proper credit amount" + assert item.debit == 0.0, "Journal items have not proper debit amount" From a4eb2a04b56483dacfe00e999cf396c299e96104 Mon Sep 17 00:00:00 2001 From: "Harry (OpenERP)" Date: Thu, 12 Jan 2012 12:32:40 +0530 Subject: [PATCH 07/10] [REF] purchase: refactor product_id_change and rename with onchange_product_id bzr revid: hmo@tinyerp.com-20120112070240-zgsic6tjiy7j7g30 --- addons/purchase/purchase.py | 101 ++++++++++++++++++------------ addons/purchase/purchase_view.xml | 6 +- 2 files changed, 63 insertions(+), 44 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index bb748d68329..f63b86f11f2 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -697,56 +697,74 @@ class purchase_order_line(osv.osv): default.update({'state':'draft', 'move_ids':[],'invoiced':0,'invoice_lines':[]}) return super(purchase_order_line, self).copy_data(cr, uid, id, default, context) - #TOFIX: - # - name of method should "onchange_product_id" - # - docstring - # - split into small internal methods for clearity - def product_id_change(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, + + def _onchange_check_partner_pricelist(self, pricelist_id, partner_id): + return True + + def onchange_product_uom(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=False, fiscal_position_id=False, date_planned=False, name=False, price_unit=False, notes=False, context=None): + """ + onchange handler of product_uom. + """ + if not uom_id: + return {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or'', 'product_uom' : uom_id or False}} + return self.onchange_product_id(cr, uid, ids, pricelist_id, product_id, qty, uom_id, + partner_id, date_order=date_order, fiscal_position_id=fiscal_position_id, date_planned=date_planned, + name=name, price_unit=price_unit, notes=notes, context=context) + + def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, + partner_id, date_order=False, fiscal_position_id=False, date_planned=False, + name=False, price_unit=False, notes=False, context=None): + """ + onchange handler of product_id. + """ + res = {} if context is None: context = {} - - res = {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or'', 'product_uom' : uom_id or False} - uom_change = context.get('uom_change', False) + res_value = {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or'', 'product_uom' : uom_id or False} + if not product_id: + return {'value': res_value} + + product_product = self.pool.get('product.product') + product_uom = self.pool.get('product.uom') + res_partner = self.pool.get('res.partner') + product_supplierinfo = self.pool.get('product.supplierinfo') + product_pricelist = self.pool.get('product.pricelist') + account_fiscal_position = self.pool.get('account.fiscal.position') + account_tax = self.pool.get('account.tax') + + # - check for the presence of partner_id and pricelist_id if not pricelist_id: raise osv.except_osv(_('No Pricelist !'), _('You have to select a pricelist or a supplier in the purchase form !\nPlease set one before choosing a product.')) if not partner_id: raise osv.except_osv(_('No Partner!'), _('You have to select a partner in the purchase form !\nPlease set one partner before choosing a product.')) - if not product_id: - return {'value': res} - - product_uom_pool = self.pool.get('product.uom') - product_supplierinfo = self.pool.get('product.supplierinfo') - res_partner = self.pool.get('res.partner') - product_product = self.pool.get('product.product') - account_fiscal_position = self.pool.get('account.fiscal.position') - account_tax = self.pool.get('account.tax') - - # set supplier langauage in context + # - determine name and notes based on product in partner lang. lang = res_partner.browse(cr, uid, partner_id).lang if lang: context['lang'] = lang context['partner_id'] = partner_id - product = product_product.browse(cr, uid, product_id, context=context) + res_value.update({'name': product.name, 'notes': notes or product.description_purchase}) + + # - set a domain on product_uom domain = {'product_uom':[('category_id','=',product.uom_id.category_id.id)]} - res['domain'] = domain - - if uom_change and not uom_id: - return {'value': res} + res.update({'domain': domain}) + # - check that uom and product uom belong to the same category product_uom_po_id = product.uom_po_id.id if not uom_id: uom_id = product_uom_po_id - # checking UOM category - if product.uom_id.category_id.id != product_uom_pool.browse(cr, uid, uom_id).category_id.id: + if product.uom_id.category_id.id != product_uom.browse(cr, uid, uom_id, context=context).category_id.id: res.update({'warning': {'title': _('Warning'), 'message': _('Selected UOM does not have same category of default UOM')}}) uom_id = product_uom_po_id - + + res_value.update({'product_uom': uom_id}) + + # - determine product_qty and date_planned based on seller info if not date_order: date_order = time.strftime('%Y-%m-%d') @@ -758,31 +776,32 @@ class purchase_order_line(osv.osv): seller_delay = supplierinfo.delay if supplierinfo.product_uom.id != uom_id: res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier only sells this product by %s') % supplierinfo.product_uom.name }}) - min_qty = product_uom_pool._compute_qty(cr, uid, supplierinfo.product_uom.id, supplierinfo.min_qty, to_uom_id=uom_id) + min_qty = product_uom._compute_qty(cr, uid, supplierinfo.product_uom.id, supplierinfo.min_qty, to_uom_id=uom_id) if qty < min_qty: # If the supplier quantity is greater than entered from user, set minimal. res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s %s, you should not purchase less.') % (supplierinfo.min_qty, supplierinfo.product_uom.name)}}) qty = min_qty - - price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], + + dt = (datetime.strptime(date_order, '%Y-%m-%d') + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S') + res_value.update({'date_planned': date_planned or dt, 'product_qty': qty}) + + # - determine price_unit and taxes_id + price = product_pricelist.price_get(cr, uid, [pricelist_id], product.id, qty or 1.0, partner_id, { 'uom': uom_id, 'date': date_order, })[pricelist_id] - dt = (datetime.now() + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S') - - - res.update({'value': {'price_unit': price, 'name': product.name, - 'taxes_id':map(lambda x: x.id, product.supplier_taxes_id), - 'date_planned': date_planned or dt,'notes': notes or product.description_purchase, - 'product_qty': qty, - 'product_uom': uom_id}}) - + taxes = account_tax.browse(cr, uid, map(lambda x: x.id, product.supplier_taxes_id)) fpos = fiscal_position_id and account_fiscal_position.browse(cr, uid, fiscal_position_id, context=context) or False - res['value']['taxes_id'] = account_fiscal_position.map_tax(cr, uid, fpos, taxes) + taxes_ids = account_fiscal_position.map_tax(cr, uid, fpos, taxes) + res_value.update({'price_unit': price, 'taxes_id': taxes_ids}) + + + res.update({'value': res_value}) return res - product_uom_change = product_id_change + product_id_change = onchange_product_id + product_uom_change = onchange_product_uom def action_confirm(self, cr, uid, ids, context=None): self.write(cr, uid, ids, {'state': 'confirmed'}, context=context) diff --git a/addons/purchase/purchase_view.xml b/addons/purchase/purchase_view.xml index 14f5354f970..221c0b854a1 100644 --- a/addons/purchase/purchase_view.xml +++ b/addons/purchase/purchase_view.xml @@ -359,9 +359,9 @@
- - - + + + From cdabe44260423cebf266f80e0655fc3d3a15a53b Mon Sep 17 00:00:00 2001 From: "Harry (OpenERP)" Date: Thu, 12 Jan 2012 12:48:56 +0530 Subject: [PATCH 08/10] [IMP] purchase: remove unused method bzr revid: hmo@tinyerp.com-20120112071856-zh0bl7tn7zv0x21i --- addons/purchase/purchase.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 3895fd39667..908720eccd1 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -697,10 +697,6 @@ class purchase_order_line(osv.osv): default.update({'state':'draft', 'move_ids':[],'invoiced':0,'invoice_lines':[]}) return super(purchase_order_line, self).copy_data(cr, uid, id, default, context) - - def _onchange_check_partner_pricelist(self, pricelist_id, partner_id): - return True - def onchange_product_uom(self, cr, uid, ids, pricelist_id, product_id, qty, uom_id, partner_id, date_order=False, fiscal_position_id=False, date_planned=False, name=False, price_unit=False, notes=False, context=None): From f634d05b7d689a16a4625b75344c5c152763ec71 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 24 Jan 2012 13:31:04 +0100 Subject: [PATCH 09/10] [IMP] purchase: simplify a bit method onchange_product_id bzr revid: rco@openerp.com-20120124123104-l1tgpcnnthyrsn9k --- addons/purchase/purchase.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 908720eccd1..e91071a8e3f 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -715,13 +715,12 @@ class purchase_order_line(osv.osv): """ onchange handler of product_id. """ - res = {} if context is None: context = {} - res_value = {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or'', 'product_uom' : uom_id or False} + res = {'value': {'price_unit': price_unit or 0.0, 'name': name or '', 'notes': notes or '', 'product_uom' : uom_id or False}} if not product_id: - return {'value': res_value} + return res product_product = self.pool.get('product.product') product_uom = self.pool.get('product.uom') @@ -741,11 +740,10 @@ class purchase_order_line(osv.osv): lang = res_partner.browse(cr, uid, partner_id).lang context_partner = {'lang': lang, 'partner_id': partner_id} product = product_product.browse(cr, uid, product_id, context=context_partner) - res_value.update({'name': product.name, 'notes': notes or product.description_purchase}) + res['value'].update({'name': product.name, 'notes': notes or product.description_purchase}) # - set a domain on product_uom - domain = {'product_uom':[('category_id','=',product.uom_id.category_id.id)]} - res.update({'domain': domain}) + res['domain'] = {'product_uom': [('category_id','=',product.uom_id.category_id.id)]} # - check that uom and product uom belong to the same category product_uom_po_id = product.uom_po_id.id @@ -753,10 +751,10 @@ class purchase_order_line(osv.osv): uom_id = product_uom_po_id if product.uom_id.category_id.id != product_uom.browse(cr, uid, uom_id, context=context).category_id.id: - res.update({'warning': {'title': _('Warning'), 'message': _('Selected UOM does not have same category of default UOM')}}) + res['warning'] = {'title': _('Warning'), 'message': _('Selected UOM does not belong to the same category as the product UOM')} uom_id = product_uom_po_id - res_value.update({'product_uom': uom_id}) + res['value'].update({'product_uom': uom_id}) # - determine product_qty and date_planned based on seller info if not date_order: @@ -768,29 +766,24 @@ class purchase_order_line(osv.osv): for supplierinfo in product_supplierinfo.browse(cr, uid, supplierinfo_ids, context=context): seller_delay = supplierinfo.delay if supplierinfo.product_uom.id != uom_id: - res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier only sells this product by %s') % supplierinfo.product_uom.name }}) + res['warning'] = {'title': _('Warning'), 'message': _('The selected supplier only sells this product by %s') % supplierinfo.product_uom.name } min_qty = product_uom._compute_qty(cr, uid, supplierinfo.product_uom.id, supplierinfo.min_qty, to_uom_id=uom_id) if qty < min_qty: # If the supplier quantity is greater than entered from user, set minimal. - res.update({'warning': {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s %s, you should not purchase less.') % (supplierinfo.min_qty, supplierinfo.product_uom.name)}}) + res['warning'] = {'title': _('Warning'), 'message': _('The selected supplier has a minimal quantity set to %s %s, you should not purchase less.') % (supplierinfo.min_qty, supplierinfo.product_uom.name)} qty = min_qty dt = (datetime.strptime(date_order, '%Y-%m-%d') + relativedelta(days=int(seller_delay) or 0.0)).strftime('%Y-%m-%d %H:%M:%S') - res_value.update({'date_planned': date_planned or dt, 'product_qty': qty}) + res['value'].update({'date_planned': date_planned or dt, 'product_qty': qty}) # - determine price_unit and taxes_id price = product_pricelist.price_get(cr, uid, [pricelist_id], - product.id, qty or 1.0, partner_id, { - 'uom': uom_id, - 'date': date_order, - })[pricelist_id] + product.id, qty or 1.0, partner_id, {'uom': uom_id, 'date': date_order})[pricelist_id] taxes = account_tax.browse(cr, uid, map(lambda x: x.id, product.supplier_taxes_id)) fpos = fiscal_position_id and account_fiscal_position.browse(cr, uid, fiscal_position_id, context=context) or False taxes_ids = account_fiscal_position.map_tax(cr, uid, fpos, taxes) - res_value.update({'price_unit': price, 'taxes_id': taxes_ids}) + res['value'].update({'price_unit': price, 'taxes_id': taxes_ids}) - - res.update({'value': res_value}) return res product_id_change = onchange_product_id From 4f6f2e2de2fd633154db9eda2b2f2e9c01630101 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 24 Jan 2012 13:34:21 +0100 Subject: [PATCH 10/10] [IMP] stock/test: improve English bzr revid: rco@openerp.com-20120124123421-z3qy9cria4ftkbss --- addons/stock/test/shipment.yml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/addons/stock/test/shipment.yml b/addons/stock/test/shipment.yml index 6482668bfae..d833409df51 100644 --- a/addons/stock/test/shipment.yml +++ b/addons/stock/test/shipment.yml @@ -48,7 +48,7 @@ assert backorder, "Backorder should be created after partial shipment." assert backorder.state == 'done', "Backorder should be close after received." for move_line in backorder.move_lines: - assert move_line.product_qty == 40, "Qty in backorder is not correspond." + assert move_line.product_qty == 40, "Qty in backorder does not correspond." assert move_line.state == 'done', "Move line of backorder should be closed." - I receive another 10kgm Ice-cream. @@ -72,7 +72,7 @@ shipment = self.browse(cr, uid, ref("incomming_shipment")) assert shipment.state == 'done', "shipment should be close after received." for move_line in shipment.move_lines: - assert move_line.product_qty == 10, "Qty is not correspond." + assert move_line.product_qty == 10, "Qty does not correspond." assert move_line.state == 'done', "Move line should be closed." - @@ -111,8 +111,8 @@ - !python {model: product.product}: | product = self.browse(cr, uid, ref('product_icecream'), context=context) - assert product.qty_available == 140, "Stock is not correspond." - assert product.virtual_available == 10, "Vitual stock is not correspond." + assert product.qty_available == 140, "Stock does not correspond." + assert product.virtual_available == 10, "Vitual stock does not correspond." - I split incomming shipment into lots. each lot contain 10 kgm Ice-cream. @@ -146,8 +146,8 @@ move_ids = self.search(cr, uid, [('location_dest_id','=',ref('location_refrigerator')),('prodlot_id','in',lot_ids)]) assert len(move_ids) == 4, 'move lines are not correspond per prodcution lot after splited.' for move in self.browse(cr, uid, move_ids, context=context): - assert move.prodlot_id.name in ['incoming_lot0', 'incoming_lot1', 'incoming_lot2', 'incoming_lot3'], "lot is not correspond." - assert move.product_qty == 10, "qty is not correspond per production lot." + assert move.prodlot_id.name in ['incoming_lot0', 'incoming_lot1', 'incoming_lot2', 'incoming_lot3'], "lot does not correspond." + assert move.product_qty == 10, "qty does not correspond per production lot." context.update({'active_model':'stock.move', 'active_id':move_ids[0],'active_ids': move_ids}) - I check the stock valuation account entries. @@ -161,11 +161,11 @@ for account_move_line in account_move.line_id: for stock_move in incomming_shipment.move_lines: if account_move_line.account_id.id == stock_move.product_id.property_stock_account_input.id: - assert account_move_line.credit == 800.0, "Credit amount is not correspond." - assert account_move_line.debit == 0.0, "Debit amount is not correspond." + assert account_move_line.credit == 800.0, "Credit amount does not correspond." + assert account_move_line.debit == 0.0, "Debit amount does not correspond." else: - assert account_move_line.credit == 0.0, "Credit amount is not correspond." - assert account_move_line.debit == 800.0, "Debit amount is not correspond." + assert account_move_line.credit == 0.0, "Credit amount does not correspond." + assert account_move_line.debit == 800.0, "Debit amount does not correspond." - I consume 1 kgm ice-cream from each incoming lots into internal production. - @@ -189,19 +189,19 @@ !python {model: stock.location}: | ctx = {'product_id': ref('product_icecream')} refrigerator_location = self.browse(cr, uid, ref('location_refrigerator'), context=ctx) - assert refrigerator_location.stock_real == 131.96, 'stock is not correspond in refrigerator location.' + assert refrigerator_location.stock_real == 131.96, 'stock does not correspond in refrigerator location.' scrapped_location = self.browse(cr, uid, ref('stock_location_scrapped'), context=ctx) - assert scrapped_location.stock_real == 0.010*4, 'scraped stock is not correspond in scrap location.' + assert scrapped_location.stock_real == 0.010*4, 'scraped stock does not correspond in scrap location.' production_location = self.browse(cr, uid, ref('location_production'), context=ctx) - assert production_location.stock_real == 1*4, 'consume stock is not correspond in production location.' #TOFIX: consume stock is not updated in default production location of product. + assert production_location.stock_real == 1*4, 'consume stock does not correspond in production location.' #TOFIX: consume stock is not updated in default production location of product. - I check availabile stock after consumed and scraped. - !python {model: product.product}: | product = self.browse(cr, uid, ref('product_icecream'), context=context) - assert product.qty_available == 131.96, "Stock is not correspond." - assert round(product.virtual_available, 2) == 1.96, "Vitual stock is not correspond." + assert product.qty_available == 131.96, "Stock does not correspond." + assert round(product.virtual_available, 2) == 1.96, "Vitual stock does not correspond." - I trace all incoming lots. - @@ -276,5 +276,5 @@ - !python {model: product.product}: | product = self.browse(cr, uid, ref('product_icecream'), context=context) - assert round(product.qty_available, 2) == 1.96, "Stock is not correspond." - assert round(product.virtual_available, 2) == 1.96, "Vitual stock is not correspond." + assert round(product.qty_available, 2) == 1.96, "Stock does not correspond." + assert round(product.virtual_available, 2) == 1.96, "Vitual stock does not correspond."