From a0670b5b99a6e5f3b85270c80e292375ced2c21b Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Thu, 7 Aug 2014 13:00:17 +0200 Subject: [PATCH 01/20] fix #1253 --- addons/stock_account/stock.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py index 9679bf2a72f..d8ff83ca27b 100644 --- a/addons/stock_account/stock.py +++ b/addons/stock_account/stock.py @@ -197,10 +197,23 @@ class stock_picking(osv.osv): @param type: Type invoice to be created @return: Ids of created invoices for the pickings """ + saleorder_model = self.pool['sale.order'] context = context or {} todo = {} + import pudb + pudb.set_trace() for picking in self.browse(cr, uid, ids, context=context): - key = group and picking.id or True + #grouping is based on the invoiced partner + if group: + saleorder_ids = saleorder_model.search(cr, uid, [('procurement_group_id' ,'=', picking.group_id.id)], context=context) + saleorders = saleorder_model.browse(cr, uid, saleorder_ids, context=context) + if saleorders and saleorders[0]: + saleorder = saleorders[0] + key = "%s" % saleorder.partner_invoice_id.id + else: + key = "Pick %s" % picking.id + else: + key = picking.id for move in picking.move_lines: if move.invoice_state == '2binvoiced': if (move.state != 'cancel') and not move.scrapped: From 2bd1ec9e6b7af75f8c66419ecfccdf3c0c7fbacd Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Thu, 7 Aug 2014 13:02:34 +0200 Subject: [PATCH 02/20] remove pudb --- addons/stock_account/stock.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py index d8ff83ca27b..05f0fe3f6ce 100644 --- a/addons/stock_account/stock.py +++ b/addons/stock_account/stock.py @@ -200,8 +200,7 @@ class stock_picking(osv.osv): saleorder_model = self.pool['sale.order'] context = context or {} todo = {} - import pudb - pudb.set_trace() + for picking in self.browse(cr, uid, ids, context=context): #grouping is based on the invoiced partner if group: From c2b7bca4867d6ce74253dd87d4890bda510f53b3 Mon Sep 17 00:00:00 2001 From: Nicolas Seinlet Date: Fri, 8 Aug 2014 14:15:13 +0200 Subject: [PATCH 03/20] - Fix #1253 - avoid using sale objects in stock_account module - check the purchase side --- addons/purchase/stock.py | 8 ++++++++ addons/sale_stock/sale_stock.py | 11 +++++++++++ addons/stock_account/stock.py | 18 ++++++++++-------- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py index a966ac8308f..12a18984361 100644 --- a/addons/purchase/stock.py +++ b/addons/purchase/stock.py @@ -83,6 +83,14 @@ class stock_move(osv.osv): class stock_picking(osv.osv): _inherit = 'stock.picking' + def _get_partner_to_invoice(self, cr, uid, picking, context=None): + """ Inherit the original function of the 'stock' module + We select the partner of the purchase order as the partner of the invoice + """ + if picking.move_lines and picking.move_lines[0] and picking.move_lines[0].purchase_line_id: + return picking.move_lines[0].purchase_line_id.order_id.partner_id and picking.move_lines[0].purchase_line_id.order_id.partner_id.id + return super(stock_picking, self)._get_partner_to_invoice(cr, uid, picking, context=context) + def _get_to_invoice(self, cr, uid, ids, name, args, context=None): res = {} for picking in self.browse(cr, uid, ids, context=context): diff --git a/addons/sale_stock/sale_stock.py b/addons/sale_stock/sale_stock.py index 9e409f8be31..f2c6f529dcc 100644 --- a/addons/sale_stock/sale_stock.py +++ b/addons/sale_stock/sale_stock.py @@ -396,6 +396,17 @@ class stock_location_route(osv.osv): class stock_picking(osv.osv): _inherit = "stock.picking" + def _get_partner_to_invoice(self, cr, uid, picking, context=None): + """ Inherit the original function of the 'stock' module + We select the partner of the sales order as the partner of the customer invoice + """ + saleorder_ids = self.pool['sale.order'].search(cr, uid, [('procurement_group_id' ,'=', picking.group_id.id)], context=context) + saleorders = self.pool['sale.order'].browse(cr, uid, saleorder_ids, context=context) + if saleorders and saleorders[0]: + saleorder = saleorders[0] + return saleorder.partner_invoice_id.id + return super(stock_picking, self)._get_partner_to_invoice(cr, uid, picking, context=context) + def _get_sale_id(self, cr, uid, ids, name, args, context=None): sale_obj = self.pool.get("sale.order") res = {} diff --git a/addons/stock_account/stock.py b/addons/stock_account/stock.py index 05f0fe3f6ce..e6a26bd9d64 100644 --- a/addons/stock_account/stock.py +++ b/addons/stock_account/stock.py @@ -190,6 +190,14 @@ class stock_picking(osv.osv): invoice_obj = self.pool.get('account.invoice') return invoice_obj.create(cr, uid, vals, context=context) + def _get_partner_to_invoice(self, cr, uid, picking, context=None): + """ Gets the partner that will be invoiced + Note that this function is inherited in the sale and purchase modules + @param picking: object of the picking for which we are selecting the partner to invoice + @return: object of the partner to invoice + """ + return picking.partner_id and picking.partner_id.id + def action_invoice_create(self, cr, uid, ids, journal_id, group=False, type='out_invoice', context=None): """ Creates invoice based on the invoice state selected for picking. @param journal_id: Id of journal @@ -197,20 +205,14 @@ class stock_picking(osv.osv): @param type: Type invoice to be created @return: Ids of created invoices for the pickings """ - saleorder_model = self.pool['sale.order'] context = context or {} todo = {} for picking in self.browse(cr, uid, ids, context=context): + partner = self._get_partner_to_invoice(cr, uid, picking, context) #grouping is based on the invoiced partner if group: - saleorder_ids = saleorder_model.search(cr, uid, [('procurement_group_id' ,'=', picking.group_id.id)], context=context) - saleorders = saleorder_model.browse(cr, uid, saleorder_ids, context=context) - if saleorders and saleorders[0]: - saleorder = saleorders[0] - key = "%s" % saleorder.partner_invoice_id.id - else: - key = "Pick %s" % picking.id + key = partner else: key = picking.id for move in picking.move_lines: From 6553e2230652c769a57dd34095b8fb543da778a7 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Fri, 8 Aug 2014 17:22:14 +0200 Subject: [PATCH 04/20] [WIP] Create procurement when Phantom --- addons/mrp/mrp.py | 26 ++++++++++- addons/mrp/mrp_view.xml | 7 ++- addons/mrp/stock.py | 50 ++++++++++++++++------ addons/product/product.py | 8 ++++ addons/sale_service/models/sale_service.py | 11 ++++- addons/sale_stock/sale_stock.py | 11 +++++ addons/stock_account/product_view.xml | 4 +- 7 files changed, 95 insertions(+), 22 deletions(-) diff --git a/addons/mrp/mrp.py b/addons/mrp/mrp.py index 2ede7b27b9d..a8c39c7a09c 100644 --- a/addons/mrp/mrp.py +++ b/addons/mrp/mrp.py @@ -1115,6 +1115,26 @@ class mrp_production(osv.osv): def _make_production_consume_line(self, cr, uid, line, context=None): return self._make_consume_line_from_data(cr, uid, line.production_id, line.product_id, line.product_uom.id, line.product_qty, line.product_uos.id, line.product_uos_qty, context=context) + + def _make_service_procurement(self, cr, uid, line, context=None): + prod_obj = self.pool.get('product.product') + if prod_obj.need_procurement(cr, uid, [line.product_id.id], context=context): + vals = { + 'name': line.production_id.name, + 'origin': line.production_id.name, + 'company_id': line.production_id.company_id.id, + 'date_planned': line.production_id.date_planned, + 'product_id': line.product_id.id, + 'product_qty': line.product_qty, + 'product_uom': line.product_uom.id, + 'product_uos_qty': line.product_uos_qty, + 'product_uos': line.product_uos.id, + } + proc_obj = self.pool.get("procurement.order") + proc = proc_obj.create(cr, uid, vals, context=context) + proc_obj.run(cr, uid, [proc], context=context) + + def action_confirm(self, cr, uid, ids, context=None): """ Confirms production order. @return: Newly generated Shipment Id. @@ -1126,7 +1146,11 @@ class mrp_production(osv.osv): stock_moves = [] for line in production.product_lines: - stock_move_id = self._make_production_consume_line(cr, uid, line, context=context) + if line.product_id.type != 'service': + stock_move_id = self._make_production_consume_line(cr, uid, line, context=context) + else: + self._make_service_procurement(cr, uid, line, context=context) + stock_move_id = False if stock_move_id: stock_moves.append(stock_move_id) if stock_moves: diff --git a/addons/mrp/mrp_view.xml b/addons/mrp/mrp_view.xml index bd622cb4a99..81c78858052 100644 --- a/addons/mrp/mrp_view.xml +++ b/addons/mrp/mrp_view.xml @@ -347,9 +347,8 @@
- - - + +