From 6f8546dfb572a32f76db7e9ed3a03b1ed354270d Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 11 Dec 2014 18:32:26 +0100 Subject: [PATCH] [FIX] Make sure we can select dropship on purchase order and see the related customer and invoicing based on shipments works for sale only [FIX] Sale should lead to invoicing [IMP] Journal should not depend on picking type code when in dropship Make sure drop shipment with invoicing on sale orders only, works. Also the picking type of dropshipping should be incoming. This makes it possible to select it on the purchase order. This also fixes #3421. And we can create a dropship from a purchase only. (not the good way) For this, we make the invoicing based on the shipment look at the purchase related and not on its picking type code as the picking type of dropshipping is changed back to incoming. The purchase order will also show the customer address when in a dropship case. Closes #3421 --- addons/purchase/purchase.py | 9 +++++---- addons/purchase/purchase_view.xml | 6 +++--- addons/stock_dropshipping/stock_dropshipping.xml | 2 +- .../wizard/stock_invoice_onshipping.py | 9 ++++++--- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index a2b56e48249..8a39ce82e10 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -294,7 +294,8 @@ class purchase_order(osv.osv): 'bid_validity': fields.date('Bid Valid Until', help="Date on which the bid expired"), 'picking_type_id': fields.many2one('stock.picking.type', 'Deliver To', help="This will determine picking type of incoming shipment", required=True, states={'confirmed': [('readonly', True)], 'approved': [('readonly', True)], 'done': [('readonly', True)]}), - 'related_location_id': fields.related('picking_type_id', 'default_location_dest_id', type='many2one', relation='stock.location', string="Related location", store=True), + 'related_location_id': fields.related('picking_type_id', 'default_location_dest_id', type='many2one', relation='stock.location', string="Related location", store=True), + 'related_usage': fields.related('location_id', 'usage', type='char'), 'shipment_count': fields.function(_count_all, type='integer', string='Incoming Shipments', multi=True), 'invoice_count': fields.function(_count_all, type='integer', string='Invoices', multi=True) } @@ -380,8 +381,8 @@ class purchase_order(osv.osv): if picking_type_id: picktype = self.pool.get("stock.picking.type").browse(cr, uid, picking_type_id, context=context) if picktype.default_location_dest_id: - value.update({'location_id': picktype.default_location_dest_id.id}) - value.update({'related_location_id': picktype.default_location_dest_id and picktype.default_location_dest_id.id or False}) + value.update({'location_id': picktype.default_location_dest_id.id, 'related_usage': picktype.default_location_dest_id.usage}) + value.update({'related_location_id': picktype.default_location_dest_id.id}) return {'value': value} def onchange_partner_id(self, cr, uid, ids, partner_id, context=None): @@ -749,7 +750,7 @@ class purchase_order(osv.osv): 'move_dest_id': procurement.move_dest_id.id, #move destination is same as procurement destination 'group_id': procurement.group_id.id or group_id, #move group is same as group of procurements if it exists, otherwise take another group 'procurement_id': procurement.id, - 'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state=='picking' and '2binvoiced') or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale + 'invoice_state': procurement.rule_id.invoice_state or (procurement.location_id and procurement.location_id.usage == 'customer' and procurement.invoice_state=='2binvoiced' and '2binvoiced') or (order.invoice_method == 'picking' and '2binvoiced') or 'none', #dropship case takes from sale 'propagate': procurement.rule_id.propagate, }) diff_quantity -= min(procurement_qty, diff_quantity) diff --git a/addons/purchase/purchase_view.xml b/addons/purchase/purchase_view.xml index b422df9b2ee..53c2e692ca1 100644 --- a/addons/purchase/purchase_view.xml +++ b/addons/purchase/purchase_view.xml @@ -226,10 +226,10 @@ - + diff --git a/addons/stock_dropshipping/stock_dropshipping.xml b/addons/stock_dropshipping/stock_dropshipping.xml index de1de472d20..b161685eea3 100644 --- a/addons/stock_dropshipping/stock_dropshipping.xml +++ b/addons/stock_dropshipping/stock_dropshipping.xml @@ -14,7 +14,7 @@ Dropship - outgoing + incoming diff --git a/addons/stock_dropshipping/wizard/stock_invoice_onshipping.py b/addons/stock_dropshipping/wizard/stock_invoice_onshipping.py index 6d0a7fc71f3..ca67ec2a11d 100644 --- a/addons/stock_dropshipping/wizard/stock_invoice_onshipping.py +++ b/addons/stock_dropshipping/wizard/stock_invoice_onshipping.py @@ -34,9 +34,12 @@ class stock_invoice_onshipping(osv.osv_memory): pick = pickings and pickings[0] src_usage = pick.move_lines[0].location_id.usage dest_usage = pick.move_lines[0].location_dest_id.usage - pick_purchase = pick.move_lines and pick.move_lines[0].purchase_line_id and pick.move_lines[0].purchase_line_id.order_id.invoice_method == 'picking' - if pick.picking_type_id.code == 'outgoing' and src_usage == 'supplier' and dest_usage == 'customer' and pick_purchase: - return 'purchase' + if src_usage == 'supplier' and dest_usage == 'customer': + pick_purchase = pick.move_lines and pick.move_lines[0].purchase_line_id and pick.move_lines[0].purchase_line_id.order_id.invoice_method == 'picking' + if pick_purchase: + return 'purchase' + else: + return 'sale' else: return super(stock_invoice_onshipping, self)._get_journal_type(cr, uid, context=context)