From 90319d5e2a248e70e342d691fbce3c19ebbf09d2 Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 21 Oct 2013 11:55:44 +0200 Subject: [PATCH] [FIX] purchase: create suppier invoice based on incomming shipment + [FIX] stock_complex_route: fixed yaml test bzr revid: qdp-launchpad@openerp.com-20131021095544-i0n6fd8jz31jo1l6 --- addons/purchase/stock.py | 32 ++++++++++++++----- addons/purchase/stock_view.xml | 16 ++-------- addons/stock/stock.py | 2 +- addons/stock_complex_routes/test/dropship.yml | 5 +-- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/addons/purchase/stock.py b/addons/purchase/stock.py index 34d8c8df595..c6fd849854f 100644 --- a/addons/purchase/stock.py +++ b/addons/purchase/stock.py @@ -38,19 +38,35 @@ class stock_move(osv.osv): workflow.trg_trigger(uid, 'stock.move', id, cr) return res -# -# Inherit of picking to add the link to the PO -# class stock_picking(osv.osv): _inherit = 'stock.picking' + + def _get_to_invoice(self, cr, uid, ids, name, args, context=None): + res = {} + for picking in self.browse(cr, uid, ids, context=context): + res[picking.id] = False + for move in picking.move_lines: + if move.purchase_line_id and move.purchase_line_id.order_id.invoice_method == 'picking': + if not move.move_orig_ids: + res[picking.id] = True + return res + + def _get_picking_to_recompute(self, cr, uid, ids, context=None): + picking_ids = set() + for move in self.pool.get('stock.move').browse(cr, uid, ids, context=context): + if move.picking_id: + picking_ids.add(move.picking_id.id) + return list(picking_ids) + _columns = { - 'purchase_id': fields.many2one('purchase.order', 'Purchase Order', - ondelete='set null', select=True), + 'reception_to_invoice': fields.function(_get_to_invoice, type='boolean', string='Invoiceable on incoming shipment?', + help='Does the picking contains some moves related to a purchase order invoiceable on the reception?', + store={ + 'stock.picking': (lambda self, cr, uid, ids, c={}: ids, ['move_lines'], 10), + 'stock.move': (_get_picking_to_recompute, ['purchase_line_id', 'picking_id'], 10), + }), } - _defaults = { - 'purchase_id': False, - } # TODO: Invoice based on receptions # Here is how it should work: diff --git a/addons/purchase/stock_view.xml b/addons/purchase/stock_view.xml index 18ad626b84b..9e8f321cdfd 100644 --- a/addons/purchase/stock_view.xml +++ b/addons/purchase/stock_view.xml @@ -12,24 +12,13 @@ - - Picking Inherited - stock.picking - - - - - - - - stock.picking.in.search.inherit stock.picking - + @@ -58,8 +47,7 @@ ir.actions.act_window form tree,form,calendar - [('purchase_id.invoice_method','=','picking')] - {"default_type": "in", "contact_display": "partner_address", "search_default_done": 1, "search_default_to_invoice": 1} + {"default_type": "in", "contact_display": "partner_address", "search_default_done": 1, "search_default_reception_to_invoice": 1}

diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 8cbe8307f15..d47b2fc1d63 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -1310,7 +1310,7 @@ class stock_move(osv.osv): 'move_dest_id': fields.many2one('stock.move', 'Destination Move', help="Optional: next stock move when chaining them", select=True), 'move_orig_ids': fields.one2many('stock.move', 'move_dest_id', 'Original Move', help="Optional: previous stock move when chaining them", select=True), - 'picking_id': fields.many2one('stock.picking', 'Reference', select=True,states={'done': [('readonly', True)]}), + 'picking_id': fields.many2one('stock.picking', 'Reference', select=True, states={'done': [('readonly', True)]}), 'picking_priority': fields.related('picking_id','priority', type='selection', selection=[('0','Low'),('1','Normal'),('2','High')], string='Picking Priority'), 'note': fields.text('Notes'), 'state': fields.selection([('draft', 'New'), diff --git a/addons/stock_complex_routes/test/dropship.yml b/addons/stock_complex_routes/test/dropship.yml index ab2d972af2b..502231df81a 100644 --- a/addons/stock_complex_routes/test/dropship.yml +++ b/addons/stock_complex_routes/test/dropship.yml @@ -71,8 +71,9 @@ - !python {model: stock.picking}: | po_id = self.pool.get('purchase.order').search(cr, uid, [('partner_id', '=', ref('supplier_dropship'))]) - picking_id = self.search(cr, uid, [('purchase_id', '=', po_id[0])]) - self.do_partial(cr, uid, picking_id) + assert po_id and len(po_id) == 1, 'Problem with the Purchase Order detected' + picking_ids = [pick.id for pick in self.pool.get('purchase.order').browse(cr, uid, po_id[0]).picking_ids] + self.do_partial(cr, uid, picking_ids) - Check one quant was created in Customers location with 200 pieces and one move in the history_ids -