From 038aee2d06f89d97b075d825f9f862b3aabf3dfd Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Wed, 21 Aug 2013 15:07:42 +0530 Subject: [PATCH 1/7] [IMP] improved the code bzr revid: bde@tinyerp.com-20130821093742-rt0lvwdw98aiwx3w --- addons/stock/procurement.py | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index 4eeca78e0a1..e0c93957459 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -97,7 +97,6 @@ class procurement_order(osv.osv): move_obj = self.pool.get('stock.move') move_dict = self._run_move_create(cr, uid, procurement, context=context) move_id = move_obj.create(cr, uid, move_dict, context=context) - self.write(cr, uid, procurement.id, {'move_dest_id': move_id}, context=context) move_obj.action_confirm(cr, uid, [move_id], context=context) return move_id return super(procurement_order, self)._run(cr, uid, procurement, context) From 95c6b17bdef105c13627986809247bc899e2fe97 Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Thu, 22 Aug 2013 15:59:52 +0530 Subject: [PATCH 2/7] [IMP] improved the code bzr revid: bde@tinyerp.com-20130822102952-3kep0jyz0gnbq5fx --- addons/stock/procurement.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index e0c93957459..eae63e50642 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -86,7 +86,7 @@ class procurement_order(osv.osv): 'rule_id': procurement.rule_id.id, 'origin': procurement.origin, 'picking_type_id': procurement.rule_id.picking_type_id.id, - 'price_unit': procurement.sale_line_id.product_id.standard_price + 'price_unit': procurement.sale_line_id.product_id and procurement.sale_line_id.product_id.standard_price, } def _run(self, cr, uid, procurement, context=None): From b42f8b53db1c84c1e07e43bae27347565fef7497 Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Fri, 23 Aug 2013 12:21:19 +0530 Subject: [PATCH 3/7] [IMP] improved _get_orders method and added _get_orders_procurements method to complete the flow of Sale Order bzr revid: bde@tinyerp.com-20130823065119-6yje7t9nyfi3r5fl --- addons/sale_stock/sale_stock.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 3163365ffc0..920be1793c1 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -57,11 +57,18 @@ class sale_order(osv.osv): def _get_orders(self, cr, uid, ids, context=None): res = set() - for move in self.browse(cr, uid, ids, context=context): + for move in self.pool.get('stock.move').browse(cr, uid, ids, context=context): if move.procurement_id and move.procurement_id.sale_line_id: res.add(move.procurement_id.sale_line_id.order_id.id) return list(res) - + + def _get_orders_procurements(self, cr, uid, ids, context=None): + res = set() + for proc in self.pool.get('procurement.order').browse(cr, uid, ids, context=context): + if proc.sale_line_id: + res.add(proc.sale_line_id.order_id.id) + return list(res) + def _get_picking_ids(self, cr, uid, ids, name, args, context=None): res = {} for sale in self.browse(cr, uid, ids, context=context): @@ -107,7 +114,10 @@ class sale_order(osv.osv): ('prepaid', 'Before Delivery'), ], 'Create Invoice', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="""On demand: A draft invoice can be created from the sales order when needed. \nOn delivery order: A draft invoice can be created from the delivery order when the products have been delivered. \nBefore delivery: A draft invoice is created from the sales order and must be paid before the products can be delivered."""), - 'shipped': fields.function(_get_shipped, string='Delivered', type='boolean', store={'stock.move': (_get_orders, ['state'], 10)}), + 'shipped': fields.function(_get_shipped, string='Delivered', type='boolean', store={ + 'stock.move': (_get_orders, ['state'], 10), + 'procurement.order': (_get_orders_procurements, ['state'], 10) + }), 'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse', required=True), 'picking_ids': fields.function(_get_picking_ids, method=True, type='one2many', relation='stock.picking', string='Picking associated to this sale'), } @@ -223,7 +233,7 @@ class sale_order(osv.osv): self.pool.get('sale.order.line').write(cr, uid, write_done_ids, {'state': 'done'}) if write_cancel_ids: self.pool.get('sale.order.line').write(cr, uid, write_cancel_ids, {'state': 'exception'}) - + if mode == 'finished': return finished elif mode == 'canceled': @@ -265,7 +275,7 @@ class sale_order(osv.osv): class sale_order_line(osv.osv): _inherit = 'sale.order.line' - + def _number_packages(self, cr, uid, ids, field_name, arg, context=None): res = {} for line in self.browse(cr, uid, ids, context=context): From b97a9da42dfdbd5ec1bc76f2f0860e4f5f0cce0d Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Mon, 26 Aug 2013 12:44:05 +0530 Subject: [PATCH 4/7] [REVERT] reverted the changes in _get_orders method bzr revid: bde@tinyerp.com-20130826071405-yax8hqw0esrll766 --- addons/sale_stock/sale_stock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 920be1793c1..015347449ae 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -57,7 +57,7 @@ class sale_order(osv.osv): def _get_orders(self, cr, uid, ids, context=None): res = set() - for move in self.pool.get('stock.move').browse(cr, uid, ids, context=context): + for move in self.browse(cr, uid, ids, context=context): if move.procurement_id and move.procurement_id.sale_line_id: res.add(move.procurement_id.sale_line_id.order_id.id) return list(res) From 30685ddffb634397dc91e3398a0fe0a816d142db Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Mon, 26 Aug 2013 15:49:14 +0530 Subject: [PATCH 5/7] [IMP] overrided _run_move_create method to get standard price of a product bzr revid: bde@tinyerp.com-20130826101914-24jt4eqx8zqpvvbg --- addons/sale/sale.py | 8 +++++++- addons/stock/procurement.py | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index f733cfd9ff1..fa041b11370 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1082,4 +1082,10 @@ class procurement_order(osv.osv): _defaults = { 'invoice_state': 'none', } - + + def _run_move_create(self, cr, uid, procurement, context=None): + res = super(procurement_order, self)._run_move_create(cr, uid, procurement, context=context) + res.update({ + 'price_unit': procurement.sale_line_id and procurement.sale_line_id.product_id and procurement.sale_line_id.product_id.standard_price or 0.0, + }) + return res diff --git a/addons/stock/procurement.py b/addons/stock/procurement.py index eae63e50642..7f36871b9d1 100644 --- a/addons/stock/procurement.py +++ b/addons/stock/procurement.py @@ -86,7 +86,6 @@ class procurement_order(osv.osv): 'rule_id': procurement.rule_id.id, 'origin': procurement.origin, 'picking_type_id': procurement.rule_id.picking_type_id.id, - 'price_unit': procurement.sale_line_id.product_id and procurement.sale_line_id.product_id.standard_price, } def _run(self, cr, uid, procurement, context=None): From cc4764f48fde77fc37f77d6e6e318a811da01e60 Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Tue, 27 Aug 2013 14:42:17 +0530 Subject: [PATCH 6/7] [REVERT] reverted price_unit changes bzr revid: bde@tinyerp.com-20130827091217-9l7wbz2v6weaxuoz --- addons/sale/sale.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 354a3b48301..83ec686b898 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -1082,10 +1082,4 @@ class procurement_order(osv.osv): _defaults = { 'invoice_state': 'none', } - - def _run_move_create(self, cr, uid, procurement, context=None): - res = super(procurement_order, self)._run_move_create(cr, uid, procurement, context=context) - res.update({ - 'price_unit': procurement.sale_line_id and procurement.sale_line_id.product_id and procurement.sale_line_id.product_id.standard_price or 0.0, - }) - return res + \ No newline at end of file From 72e1113082a87664c3f52ec25b8ced327fe896e5 Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Tue, 27 Aug 2013 15:47:09 +0530 Subject: [PATCH 7/7] [IMP] assigned picking_policy of SO in move_type of procurement.group bzr revid: bde@tinyerp.com-20130827101709-8mp60l9rke2rpcqj --- addons/sale/sale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale/sale.py b/addons/sale/sale.py index 83ec686b898..6535ed7bc6d 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -658,7 +658,7 @@ class sale_order(osv.osv): for order in self.browse(cr, uid, ids, context=context): proc_ids = [] group_id = self.pool.get("procurement.group").create(cr, uid, { - 'name': order.name, 'partner_id': order.partner_shipping_id.id + 'name': order.name, 'partner_id': order.partner_shipping_id.id, 'move_type': order.picking_policy }, context=context) order.write({'procurement_group_id': group_id}, context=context) for line in order.order_line: