diff --git a/addons/purchase/test/purchase_from_picking.yml b/addons/purchase/test/purchase_from_picking.yml index d0c1cbcb527..20dd3f0f907 100644 --- a/addons/purchase/test/purchase_from_picking.yml +++ b/addons/purchase/test/purchase_from_picking.yml @@ -122,36 +122,23 @@ I check that an entry gets created related to stock move. - !python {model: purchase.order}: | - from tools.translate import _ pur_id1=self.browse(cr, uid, ref("purchase_order_po2")) picking_obj = self.pool.get('stock.picking') ids = picking_obj.search(cr, uid, [('origin', '=', pur_id1.name)]) pick_id = picking_obj.browse(cr, uid, ids)[0] move_obj = self.pool.get('stock.move') search_id = move_obj.search(cr, uid, [('picking_id', '=', pick_id.name)]) - assert search_id, _('No Incoming Product!') -- - I check that Traceability moves are created. + assert search_id, 'No Incoming Product!' - Then I create an invoice from picking by clicking on "Create Invoice" wizard -- - I create stock invoice on shipping entry. -- - !record {model: stock.invoice.onshipping, id: stock_invoice_onshipping_0}: - invoice_date: '2010-05-11' - journal_id: account.bank_journal - type: in_invoice -- - I create Invoice. - !python {model: stock.invoice.onshipping}: | - pur_obj=self.pool.get('purchase.order') + pur_obj=self.pool.get('purchase.order') pur_id1=pur_obj.browse(cr, uid, ref("purchase_order_po2")) - picking_obj = self.pool.get('stock.picking') - ids = picking_obj.search(cr, uid, [('origin', '=', pur_id1.name)]) - self.create_invoice(cr, uid, [ref("stock_invoice_onshipping_0")], {"lang": "en_US", - "tz": False, "search_default_approved": 1, "active_model": "stock.picking", - "active_ids": ids, "active_id": ids[0], }) + pick_ids = [x.id for x in pur_id1.picking_ids] + id = self.create(cr, uid, {'invoice_date': '2010-05-11', 'journal_id': ref('account.expenses_journal')}, + {'active_ids': pick_ids}) + self.create_invoice(cr, uid, [id], {"active_ids": pick_ids}) - I check that an invoice_id field of Delivery&Invoices gets bind with the value. - diff --git a/addons/sale/test/invoice_on_shipped_qty.yml b/addons/sale/test/invoice_on_shipped_qty.yml index ab24c8541fd..3ed4387067a 100644 --- a/addons/sale/test/invoice_on_shipped_qty.yml +++ b/addons/sale/test/invoice_on_shipped_qty.yml @@ -65,24 +65,16 @@ 'product_uom': move.product_uom.id, } self.do_partial(cr, uid, [pick.id],partial_datas) -- - Then I create the invoice from the two partial picking -- - !record {model: stock.invoice.onshipping, id: stock_invoice_onshipping_6}: - invoice_date: '2010-07-17' - journal_id: account.sales_journal - type: out_invoice - Then I click on 'Create Invoices' button - !python {model: stock.invoice.onshipping}: | sale_obj = self.pool.get('sale.order') sale_id = sale_obj.browse(cr, uid, ref("sale_order_so6")) - picking_obj = self.pool.get('stock.picking') - ids = picking_obj.search(cr, uid, [('origin', '=', sale_id.name)]) - self.create_invoice(cr, uid, [ref("stock_invoice_onshipping_6")], {"lang": "en_US", - "search_default_available": 1, "tz": False, "active_model": "stock.picking", - "contact_display": "partner", "active_ids": ids, "active_id": ids[0]}) + ids = [x.id for x in sale_id.picking_ids] + wiz_id = self.create(cr, uid, {'invoice_date': '2010-07-17', 'journal_id': ref('account.sales_journal')}, + {'active_ids': ids}) + self.create_invoice(cr, uid, [wiz_id], {"active_ids": ids}) - I verify whether the invoice has been generated for SO - diff --git a/addons/sale/test/picking_order_policy.yml b/addons/sale/test/picking_order_policy.yml index c3f4ba87aaf..b12bddd7ecc 100644 --- a/addons/sale/test/picking_order_policy.yml +++ b/addons/sale/test/picking_order_policy.yml @@ -58,24 +58,16 @@ 'product_uom': move.product_uom.id, } self.do_partial(cr, uid, [pick.id],partial_datas) -- - Then I create invoice from picking -- - !record {model: stock.invoice.onshipping, id: stock_invoice_onshipping_0}: - invoice_date: '2010-07-15' - journal_id: account.sales_journal - type: out_invoice - Then I click on 'Create Invoices' button - !python {model: stock.invoice.onshipping}: | sale_obj=self.pool.get('sale.order') sale_id=sale_obj.browse(cr, uid, ref("sale_order_so7")) - picking_obj = self.pool.get('stock.picking') - ids = picking_obj.search(cr, uid, [('origin', '=', sale_id.name)]) - self.create_invoice(cr, uid, [ref("stock_invoice_onshipping_0")], {"lang": "en_US", - "search_default_available": 1, "tz": False, "active_model": "stock.picking", - "contact_display": "partner", "active_ids": ids, "active_id": ids[0]}) + ids = [x.id for x in sale_id.picking_ids] + wiz_id = self.create(cr, uid, {'invoice_date': '2010-07-15', 'journal_id': ref('account.sales_journal')}, + {'active_ids': ids}) + self.create_invoice(cr, uid, [wiz_id], {"active_ids": ids}) - I check that an invoice has been created. - diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 2adb71abb4d..39d56564806 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -781,7 +781,7 @@ stock.picking tree - + @@ -800,7 +800,7 @@ stock.picking form -
+ @@ -939,9 +939,9 @@ - - - + + + @@ -969,7 +969,7 @@ - Outgoing Orders + Outgoing Deliveries stock.picking ir.actions.act_window form diff --git a/addons/stock/wizard/stock_invoice_onshipping.py b/addons/stock/wizard/stock_invoice_onshipping.py index 7e0693b9045..d841c7cb37a 100644 --- a/addons/stock/wizard/stock_invoice_onshipping.py +++ b/addons/stock/wizard/stock_invoice_onshipping.py @@ -29,95 +29,77 @@ class stock_invoice_onshipping(osv.osv_memory): _columns = { 'journal_id': fields.many2one('account.journal', 'Destination Journal', required=True), 'group': fields.boolean("Group by partner"), - 'type': fields.selection([('out_invoice', 'Customer Invoice'), - ('in_invoice', 'Supplier Invoice'), - ('out_refund', 'Customer Refund'), - ('in_refund', 'Supplier Refund')] , 'Type', required=True), 'invoice_date': fields.date('Invoiced date'), } - def _get_type(self, cr, uid, context=None): - """ To get invoice type. - @param self: The object pointer. - @param cr: A database cursor - @param uid: ID of the user currently logged in - @param ids: The ID or list of IDs if we want more than one - @param context: A standard dictionary - @return: Invoice type - """ + def view_init(self, cr, uid, fields_list, context=None): if context is None: context = {} - picking_obj = self.pool.get('stock.picking') + res = super(stock_invoice_onshipping, self).view_init(cr, uid, fields_list, context=context) + pick_obj = self.pool.get('stock.picking') + count = 0 + active_ids = context.get('active_ids',[]) + for pick in pick_obj.browse(cr, uid, active_ids): + if pick.invoice_state != '2binvoiced': + count += 1 + if len(active_ids) == 1 and count: + raise osv.except_osv(_('Warning !'), _('This picking list does not require invoicing.')) + if len(active_ids) == count: + raise osv.except_osv(_('Warning !'), _('None of these picking lists require invoicing.')) + return res + + def _get_type(self, pick): src_usage = dest_usage = None - pick = picking_obj.browse(cr, uid, context['active_id'], context=context) - if pick.invoice_state == 'invoiced': - raise osv.except_osv(_('UserError'), _('Invoice is already created.')) - if pick.invoice_state == 'none': - raise osv.except_osv(_('UserError'), _('This picking does not require any invoicing.')) - if pick.move_lines: - src_usage = pick.move_lines[0].location_id.usage - dest_usage = pick.move_lines[0].location_dest_id.usage - if pick.type == 'out' and dest_usage == 'supplier': - type = 'in_refund' - elif pick.type == 'out' and dest_usage == 'customer': - type = 'out_invoice' - elif pick.type == 'in' and src_usage == 'supplier': - type = 'in_invoice' - elif pick.type == 'in' and src_usage == 'customer': - type = 'out_refund' - else: - type = 'out_invoice' - return type + pick_type = None + if pick.invoice_state=='2binvoiced': + if pick.move_lines: + src_usage = pick.move_lines[0].location_id.usage + dest_usage = pick.move_lines[0].location_dest_id.usage + if pick.type == 'out' and dest_usage == 'supplier': + pick_type = 'in_refund' + elif pick.type == 'out' and dest_usage == 'customer': + pick_type = 'out_invoice' + elif pick.type == 'in' and src_usage == 'supplier': + pick_type = 'in_invoice' + elif pick.type == 'in' and src_usage == 'customer': + pick_type = 'out_refund' + else: + pick_type = 'out_invoice' + return pick_type - _defaults = { - 'type': _get_type, - } - - def create_invoice(self, cr, uid, ids, context): - """ To create invoice - @param self: The object pointer. - @param cr: A database cursor - @param uid: ID of the user currently logged in - @param ids: the ID or list of IDs if we want more than one - @param context: A standard dictionary - @return: Invoice ids - """ + def create_invoice(self, cr, uid, ids, context=None): + if context is None: + context = {} result = [] picking_obj = self.pool.get('stock.picking') - mod_obj = self.pool.get('ir.model.data') - act_obj = self.pool.get('ir.actions.act_window') + onshipdata_obj = self.read(cr, uid, ids[0], ['journal_id', 'group', 'invoice_date']) + if context.get('new_picking', False): + onshipdata_obj['id'] = onshipdata_obj.new_picking + onshipdata_obj[ids] = onshipdata_obj.new_picking - for onshipdata_obj in self.read(cr, uid, ids, ['journal_id', 'group', 'type', 'invoice_date']): - if context.get('new_picking', False): - onshipdata_obj[id] = onshipdata_obj.new_picking - onshipdata_obj[ids] = onshipdata_obj.new_picking + context['date_inv'] = onshipdata_obj['invoice_date'] + invoice_ids = [] + for picking in picking_obj.browse(cr, uid, context.get('active_ids', []), context=context): + if picking.invoice_state == '2binvoiced': + res = picking_obj.action_invoice_create(cr, uid, [picking.id], + journal_id = onshipdata_obj['journal_id'], + group=onshipdata_obj['group'], + type=self._get_type(picking), + context=context) + invoice_ids.extend(res.values()) - type = onshipdata_obj['type'] - context['date_inv'] = onshipdata_obj['invoice_date'] - res = picking_obj.action_invoice_create(cr, uid,context['active_ids'], - journal_id = onshipdata_obj['journal_id'], - group=onshipdata_obj['group'], - type=type, - context=context) - invoice_ids = res.values() - if not invoice_ids: - raise osv.except_osv(_('Error'), _('Invoice is not created')) + if not invoice_ids: + raise osv.except_osv(_('Error'), _('No invoice were created')) - if type == 'out_invoice': - xml_id = 'action_invoice_tree1' - elif type == 'in_invoice': - xml_id = 'action_invoice_tree2' - elif type == 'out_refund': - xml_id = 'action_invoice_tree3' - else: - xml_id = 'action_invoice_tree4' - - result = mod_obj._get_id(cr, uid, 'account', xml_id) - id = mod_obj.read(cr, uid, result, ['res_id'], context=context) - result = act_obj.read(cr, uid, id['res_id'], context=context) - result['res_id'] = invoice_ids - result['context'] = context - return result + return { + 'domain': "[('id','in', ["+','.join(map(str,invoice_ids))+"])]", + 'name' : _('New picking invoices'), + 'view_type': 'form', + 'view_mode': 'tree,form', + 'res_model': 'account.invoice', + 'context': context, + 'type': 'ir.actions.act_window', + } stock_invoice_onshipping() diff --git a/addons/stock/wizard/stock_invoice_onshipping_view.xml b/addons/stock/wizard/stock_invoice_onshipping_view.xml index 6284121553c..6a4cfec5fca 100644 --- a/addons/stock/wizard/stock_invoice_onshipping_view.xml +++ b/addons/stock/wizard/stock_invoice_onshipping_view.xml @@ -1,36 +1,34 @@ - + Stock Invoice Onshipping stock.invoice.onshipping form - - - - - - - - - - -