From bbf8ca67fa11a3c399020413d3885f040e9ceb2d Mon Sep 17 00:00:00 2001 From: "Randhir Mayatra (OpenERP)" Date: Tue, 13 Aug 2013 10:54:24 +0530 Subject: [PATCH 01/26] [IMP] make chnages anglo_saxon_yml bzr revid: rma@tinyerp.com-20130813052424-bdolzw3yl93kggay --- .../account_anglo_saxon/test/anglo_saxon.yml | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/addons/account_anglo_saxon/test/anglo_saxon.yml b/addons/account_anglo_saxon/test/anglo_saxon.yml index 6e9ebc0068e..77dc05836bc 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon.yml @@ -123,10 +123,15 @@ - Reception is ready for process so now done the reception. - - !python {model: stock.partial.picking}: | - pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001")).picking_ids - partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]}) - self.do_partial(cr, uid, [partial_id]) + !python {model: stock.picking}: | + order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001")) + for pick in order.picking_ids: + self.pool.get('stock.pack.operation').create(cr, uid, { + 'picking_id': pick.id, + 'product_qty': 1 + }) + pick.do_partial(context=context) + - I check the Stock Interim account (Received) is credited successfully. - @@ -189,7 +194,6 @@ - !record {model: stock.picking, id: stock_picking_out001}: partner_id: base.res_partner_13 - invoice_state: 2binvoiced move_lines: - company_id: base.main_company location_id: stock.stock_location_stock @@ -198,29 +202,31 @@ product_uom: product.product_uom_unit location_dest_id: stock.stock_location_customers move_type: direct - type: out + picking_type_id: 1 - I need to check the availability of the product, So I make my picking order for processing later. - !python {model: stock.picking}: | - self.draft_force_assign(cr, uid, [ref("stock_picking_out001")], {"lang": "en_US", "search_default_available": - 1, "tz": False, "active_model": "ir.ui.menu", "contact_display": "partner", - "active_ids": [ref("stock.menu_action_picking_tree")], "active_id": ref("stock.menu_action_picking_tree"), - }) + self.action_confirm(cr, uid, [ref('stock_picking_out001')], context=context) + - I check the product availability, Product is available in the stock and ready to be sent. - !python {model: stock.picking}: | - self.action_assign(cr, uid, [ref("stock_picking_out001")], {"lang": "en_US", "search_default_available": - 1, "tz": False, "active_model": "ir.ui.menu", "contact_display": "partner", - "active_ids": [ref("stock.menu_action_picking_tree")], "active_id": ref("stock.menu_action_picking_tree"), - }) + self.action_confirm(cr, uid, [ref('stock_picking_out001')], context=context) + - I process the delivery. - - !python {model: stock.partial.picking}: | - partial_id = self.create(cr, uid, {}, context={'active_model':'stock.picking','active_ids':[ref('stock_picking_out001')]}) - self.do_partial(cr, uid, [partial_id]) + !python {model: stock.picking}: | + order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001")) + pick_order = self.pool.get('stock.picking').browse(cr, uid, ref("stock_picking_out001")) + for pick in pick_order.picking_ids: + self.pool.get('stock.pack.operation').create(cr, uid, { + 'picking_id': pick.id, + 'product_qty': 1 + }) + pick.do_partial(context=context) - I check Stock Interim account (Delivery) is debited successfully. - From ea891054bc7ea9e5de6bd759edbcccf6fef16928 Mon Sep 17 00:00:00 2001 From: "Randhir Mayatra (OpenERP)" Date: Tue, 13 Aug 2013 12:57:14 +0530 Subject: [PATCH 02/26] [IMP] improve anglo_saxon_yml bzr revid: rma@tinyerp.com-20130813072714-7apay9hbt5m0ja6o --- addons/account_anglo_saxon/test/anglo_saxon.yml | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/account_anglo_saxon/test/anglo_saxon.yml b/addons/account_anglo_saxon/test/anglo_saxon.yml index 77dc05836bc..ecb5d291535 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon.yml @@ -202,7 +202,7 @@ product_uom: product.product_uom_unit location_dest_id: stock.stock_location_customers move_type: direct - picking_type_id: 1 + picking_type_id: self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'picking_type_out', context=context).id - I need to check the availability of the product, So I make my picking order for processing later. - @@ -213,20 +213,21 @@ I check the product availability, Product is available in the stock and ready to be sent. - !python {model: stock.picking}: | - self.action_confirm(cr, uid, [ref('stock_picking_out001')], context=context) + picking = self.browse(cr, uid, ref("stock_picking_out001")) + assert picking.state == "confirmed", "Picking should be confirmed." + for move_line in picking.move_lines: + assert move_line.state == "confirmed", "Move should be confirmed." - I process the delivery. - !python {model: stock.picking}: | - order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001")) pick_order = self.pool.get('stock.picking').browse(cr, uid, ref("stock_picking_out001")) - for pick in pick_order.picking_ids: - self.pool.get('stock.pack.operation').create(cr, uid, { - 'picking_id': pick.id, - 'product_qty': 1 + self.pool.get('stock.pack.operation').create(cr, uid, { + 'picking_id': pick_order.id, + 'product_qty': 1 }) - pick.do_partial(context=context) + pick_order.do_partial(context=context) - I check Stock Interim account (Delivery) is debited successfully. - From b46d71d2b3ff56ce8c1ab9238e57caf511a5c8a2 Mon Sep 17 00:00:00 2001 From: "Randhir Mayatra (OpenERP)" Date: Tue, 13 Aug 2013 15:07:15 +0530 Subject: [PATCH 03/26] [IMP] make changes in acc_anglo_saxon_lifo bzr revid: rma@tinyerp.com-20130813093715-mqgkxfd8suxy9nye --- .../account_anglo_saxon/test/anglo_saxon.yml | 2 +- .../test/anglo_saxon_avg_fifo.yml | 38 ++++++++++--------- .../wizard/stock_invoice.py | 2 +- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/addons/account_anglo_saxon/test/anglo_saxon.yml b/addons/account_anglo_saxon/test/anglo_saxon.yml index ecb5d291535..73034497d14 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon.yml @@ -202,7 +202,7 @@ product_uom: product.product_uom_unit location_dest_id: stock.stock_location_customers move_type: direct - picking_type_id: self.pool.get('ir.model.data').get_object(cr, uid, 'stock', 'picking_type_out', context=context).id + picking_type_id: 1 - I need to check the availability of the product, So I make my picking order for processing later. - diff --git a/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml b/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml index f7d52f4f5a8..387f9bce715 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml @@ -131,10 +131,14 @@ - Reception is ready for process so now done the reception. - - !python {model: stock.partial.picking}: | - pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001_fifo")).picking_ids - partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]}) - self.do_partial(cr, uid, [partial_id]) + !python {model: stock.picking}: | + order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001_fifo")) + for pick in order.picking_ids: + self.pool.get('stock.pack.operation').create(cr, uid, { + 'picking_id': pick.id, + 'product_qty': 1 + }) + pick.do_partial(context=context) - I check the Stock Interim account (Received) is credit successfully. - @@ -192,7 +196,6 @@ - !record {model: stock.picking, id: stock_picking_out001_fifo}: partner_id: base.res_partner_13 - invoice_state: 2binvoiced move_lines: - company_id: base.main_company location_id: stock.stock_location_stock @@ -200,29 +203,30 @@ product_qty: 1.0 location_dest_id: stock.stock_location_customers move_type: direct - type: out + picking_type_id: 1 - I need to check the availability of the product, So I make my picking order for processing later. - !python {model: stock.picking}: | - self.draft_force_assign(cr, uid, [ref("stock_picking_out001_fifo")], {"lang": "en_US", "search_default_available": - 1, "tz": False, "active_model": "ir.ui.menu", "contact_display": "partner", - "active_ids": [ref("stock.menu_action_picking_tree")], "active_id": ref("stock.menu_action_picking_tree"), - }) + self.action_confirm(cr, uid, [ref('stock_picking_out001')], context=context) - I check the product availability, Product is available in the stock and ready to be sent. - !python {model: stock.picking}: | - self.action_assign(cr, uid, [ref("stock_picking_out001_fifo")], {"lang": "en_US", "search_default_available": - 1, "tz": False, "active_model": "ir.ui.menu", "contact_display": "partner", - "active_ids": [ref("stock.menu_action_picking_tree")], "active_id": ref("stock.menu_action_picking_tree"), - }) + picking = self.browse(cr, uid, ref("stock_picking_out001")) + assert picking.state == "confirmed", "Picking should be confirmed." + for move_line in picking.move_lines: + assert move_line.state == "confirmed", "Move should be confirmed." - I process the delivery. - - !python {model: stock.partial.picking}: | - partial_id = self.create(cr, uid, {}, context={'active_model':'stock.picking','active_ids':[ref('stock_picking_out001_fifo')]}) - self.do_partial(cr, uid, [partial_id]) + !python {model: stock.picking}: | + pick_order = self.pool.get('stock.picking').browse(cr, uid, ref("stock_picking_out001_fifo")) + self.pool.get('stock.pack.operation').create(cr, uid, { + 'picking_id': pick_order.id, + 'product_qty': 1 + }) + pick_order.do_partial(context=context) - I check Stock Interim account (Delivery) is debited successfully. - diff --git a/addons/stock_invoice_directly/wizard/stock_invoice.py b/addons/stock_invoice_directly/wizard/stock_invoice.py index ba41de626da..171eda3d5ab 100644 --- a/addons/stock_invoice_directly/wizard/stock_invoice.py +++ b/addons/stock_invoice_directly/wizard/stock_invoice.py @@ -22,7 +22,7 @@ from openerp.osv import fields, osv class invoice_directly(osv.osv_memory): - _inherit = 'stock.partial.picking' + _inherit = 'stock.picking' def do_partial(self, cr, uid, ids, context=None): """Launch Create invoice wizard if invoice state is To be Invoiced, From f8730cdf22d3624b589a9c049e6d815873046fb3 Mon Sep 17 00:00:00 2001 From: "Randhir Mayatra (OpenERP)" Date: Tue, 13 Aug 2013 15:43:28 +0530 Subject: [PATCH 04/26] [IMP] chnage picking_type_id bzr revid: rma@tinyerp.com-20130813101328-f3qu81wr5yda69va --- addons/account_anglo_saxon/test/anglo_saxon.yml | 2 +- addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account_anglo_saxon/test/anglo_saxon.yml b/addons/account_anglo_saxon/test/anglo_saxon.yml index 73034497d14..1223c9472d7 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon.yml @@ -202,7 +202,7 @@ product_uom: product.product_uom_unit location_dest_id: stock.stock_location_customers move_type: direct - picking_type_id: 1 + picking_type_id: stock.picking_type_out - I need to check the availability of the product, So I make my picking order for processing later. - diff --git a/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml b/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml index 387f9bce715..a98f6afc882 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml @@ -203,7 +203,7 @@ product_qty: 1.0 location_dest_id: stock.stock_location_customers move_type: direct - picking_type_id: 1 + picking_type_id: stock.picking_type_out - I need to check the availability of the product, So I make my picking order for processing later. - From ade7b86291a0dfdefec2dc52468f368c272b9930 Mon Sep 17 00:00:00 2001 From: "Randhir Mayatra (OpenERP)" Date: Tue, 13 Aug 2013 17:09:24 +0530 Subject: [PATCH 05/26] [IMP] remove extra changes bzr revid: rma@tinyerp.com-20130813113924-wwvchvxf131qtk3d --- addons/stock_invoice_directly/wizard/stock_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/stock_invoice_directly/wizard/stock_invoice.py b/addons/stock_invoice_directly/wizard/stock_invoice.py index 171eda3d5ab..ba41de626da 100644 --- a/addons/stock_invoice_directly/wizard/stock_invoice.py +++ b/addons/stock_invoice_directly/wizard/stock_invoice.py @@ -22,7 +22,7 @@ from openerp.osv import fields, osv class invoice_directly(osv.osv_memory): - _inherit = 'stock.picking' + _inherit = 'stock.partial.picking' def do_partial(self, cr, uid, ids, context=None): """Launch Create invoice wizard if invoice state is To be Invoiced, From dfeb8597fd2ee7d58c34fe3ebfdadd5047c089b8 Mon Sep 17 00:00:00 2001 From: "Randhir Mayatra (OpenERP)" Date: Wed, 14 Aug 2013 11:34:17 +0530 Subject: [PATCH 06/26] [IMP] remove stock.pack.operation opeartion on do_partial bzr revid: rma@tinyerp.com-20130814060417-b5rggizg5lgzsk2w --- addons/account_anglo_saxon/test/anglo_saxon.yml | 14 ++------------ .../test/anglo_saxon_avg_fifo.yml | 13 ++----------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/addons/account_anglo_saxon/test/anglo_saxon.yml b/addons/account_anglo_saxon/test/anglo_saxon.yml index 1223c9472d7..2dadc420e41 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon.yml @@ -124,14 +124,8 @@ Reception is ready for process so now done the reception. - !python {model: stock.picking}: | - order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001")) - for pick in order.picking_ids: - self.pool.get('stock.pack.operation').create(cr, uid, { - 'picking_id': pick.id, - 'product_qty': 1 - }) - pick.do_partial(context=context) - + order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001")).picking_ids[0] + order.do_partial(context=context) - I check the Stock Interim account (Received) is credited successfully. - @@ -223,10 +217,6 @@ - !python {model: stock.picking}: | pick_order = self.pool.get('stock.picking').browse(cr, uid, ref("stock_picking_out001")) - self.pool.get('stock.pack.operation').create(cr, uid, { - 'picking_id': pick_order.id, - 'product_qty': 1 - }) pick_order.do_partial(context=context) - I check Stock Interim account (Delivery) is debited successfully. diff --git a/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml b/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml index a98f6afc882..4e9eb5d3738 100644 --- a/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml +++ b/addons/account_anglo_saxon/test/anglo_saxon_avg_fifo.yml @@ -132,13 +132,8 @@ Reception is ready for process so now done the reception. - !python {model: stock.picking}: | - order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001_fifo")) - for pick in order.picking_ids: - self.pool.get('stock.pack.operation').create(cr, uid, { - 'picking_id': pick.id, - 'product_qty': 1 - }) - pick.do_partial(context=context) + order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_001_fifo")).picking_ids[0] + order.do_partial(context=context) - I check the Stock Interim account (Received) is credit successfully. - @@ -222,10 +217,6 @@ - !python {model: stock.picking}: | pick_order = self.pool.get('stock.picking').browse(cr, uid, ref("stock_picking_out001_fifo")) - self.pool.get('stock.pack.operation').create(cr, uid, { - 'picking_id': pick_order.id, - 'product_qty': 1 - }) pick_order.do_partial(context=context) - I check Stock Interim account (Delivery) is debited successfully. From 4af5d29679589d6b79608b17ccdcf8735a060c6c Mon Sep 17 00:00:00 2001 From: "Mansi Kariya (OpenERP Trainee)" Date: Wed, 14 Aug 2013 17:55:54 +0530 Subject: [PATCH 07/26] [IMP] Added a product and sale order. bzr revid: mansi.mk.179@gmail.com-20130814122554-dkjy8vjnmeibzqeu --- .../sale_stock/test/prepaid_order_policy.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/addons/sale_stock/test/prepaid_order_policy.yml b/addons/sale_stock/test/prepaid_order_policy.yml index e35a9a82cf9..38652cb165d 100644 --- a/addons/sale_stock/test/prepaid_order_policy.yml +++ b/addons/sale_stock/test/prepaid_order_policy.yml @@ -1,12 +1,27 @@ +- + In order to test the Prepaid Order Policy, I create a product +- + !record {model: product.product, id: product_prepaid1}: + name: 'OpenERP Documentation Book' + list_price: 60.60 +- + Now i create a sale order that uses my new product +- + !record {model: sale.order, id: sale_order_prepaid1}: + partner_id: base.res_partner_2 + order_policy: prepaid + order_line: + - product_id: sale_stock.product_prepaid1 + product_uom_qty: 10 - Now I confirm the Quotation with "Pay before delivery" policy. - - !workflow {model: sale.order, action: order_confirm, ref: sale.sale_order_4} + !workflow {model: sale.order, action: order_confirm, ref: sale_order_prepaid1} - I check that delivery order should not created before invoice is paid. - !python {model: sale.order}: | - sale_order = self.browse(cr, uid, ref("sale.sale_order_4")) + sale_order = self.browse(cr, uid, ref("sale_order_prepaid1")) assert len(sale_order.picking_ids) == False, "Delivery order should not created before invoice." assert sale_order.invoice_ids, "Invoice should be created." From 592475349ab606b1bf758f94def99246b807d135 Mon Sep 17 00:00:00 2001 From: "Jitendra Prajapati (OpenERP)" Date: Fri, 16 Aug 2013 12:33:09 +0530 Subject: [PATCH 08/26] [IMP]improve rfq2order2done yml bzr revid: prajapatijitendra7969@gmail.com-20130816070309-k1rj401ltvxbkv93 --- addons/purchase/test/process/rfq2order2done.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/purchase/test/process/rfq2order2done.yml b/addons/purchase/test/process/rfq2order2done.yml index ff9158b3c09..8a8dd946c92 100644 --- a/addons/purchase/test/process/rfq2order2done.yml +++ b/addons/purchase/test/process/rfq2order2done.yml @@ -45,10 +45,10 @@ - Reception is ready for process so now done the reception. - - !python {model: stock.partial.picking}: | + !python {model: stock.picking}: | pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_1")).picking_ids - partial_id = self.create(cr, uid, {},context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]}) - self.do_partial(cr, uid, [partial_id]) + self.do_prepare_partial(cr, uid, [pick_ids[0].id], context=context) + self.do_partial(cr, uid, [pick_ids[0].id], context=context) - I check that purchase order is shipped. - From 64fee2e674ac8484fc8f8e1021ee8ecb63911f3b Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Wed, 21 Aug 2013 10:55:28 +0530 Subject: [PATCH 09/26] [IMP] value of invoice.comment should be blank if value is False bzr revid: bde@tinyerp.com-20130821052528-wfo71cmpwcu1593r --- addons/sale_stock/test/picking_order_policy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/sale_stock/test/picking_order_policy.yml b/addons/sale_stock/test/picking_order_policy.yml index 22e26f706b7..bdad1424b2a 100644 --- a/addons/sale_stock/test/picking_order_policy.yml +++ b/addons/sale_stock/test/picking_order_policy.yml @@ -122,7 +122,7 @@ assert invoice.reference == order.client_order_ref or order.name,"Reference is not correspond." assert invoice.partner_id.id == order.partner_invoice_id.id,"Customer does not correspond." assert invoice.currency_id.id == order.pricelist_id.currency_id.id, "Currency is not correspond." - assert invoice.comment == (order.note or ''),"Note is not correspond." + assert (invoice.comment or '') == (order.note or ''),"Note is not correspond." assert invoice.journal_id.id in journal_ids,"Sales Journal is not link on Invoice." assert invoice.payment_term.id == order.payment_term.id, "Payment term is not correspond." for so_line in order.order_line: From 0d3437e753cc4b4b9a42508efc7c8ea6435d13ea Mon Sep 17 00:00:00 2001 From: "Bharat R. Devnani (OpenERP)" Date: Wed, 21 Aug 2013 11:12:53 +0530 Subject: [PATCH 10/26] [IMP] As the system creates one procurement per sale order line so checked the assert statements without for loop for procurements bzr revid: bde@tinyerp.com-20130821054253-kbtjbyosjukc9con --- addons/sale_stock/test/picking_order_policy.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/addons/sale_stock/test/picking_order_policy.yml b/addons/sale_stock/test/picking_order_policy.yml index bdad1424b2a..3cefc8e2529 100644 --- a/addons/sale_stock/test/picking_order_policy.yml +++ b/addons/sale_stock/test/picking_order_policy.yml @@ -31,15 +31,14 @@ from openerp.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT order = self.browse(cr, uid, ref("sale.sale_order_6")) for order_line in order.order_line: - procurements = order_line.procurement_ids + procurement = order_line.procurement_ids[0] date_planned = datetime.strptime(order.date_order, DEFAULT_SERVER_DATETIME_FORMAT) + relativedelta(days=order_line.delay or 0.0) date_planned = (date_planned - timedelta(days=order.company_id.security_lead)).strftime(DEFAULT_SERVER_DATETIME_FORMAT) - for procurement in procurements: - assert procurement.date_planned == date_planned, "Scheduled date is not correspond." - assert procurement.product_id.id == order_line.product_id.id, "Product is not correspond." - assert procurement.product_qty == order_line.product_uom_qty, "Qty is not correspond." - assert procurement.product_uom.id == order_line.product_uom.id, "UOM is not correspond." - assert procurement.move_dest_id.procure_method == order_line.type, "Procurement method is not correspond." + assert procurement.date_planned == date_planned, "Scheduled date is not correspond." + assert procurement.product_id.id == order_line.product_id.id, "Product is not correspond." + assert procurement.product_qty == order_line.product_uom_qty, "Qty is not correspond." + assert procurement.product_uom.id == order_line.product_uom.id, "UOM is not correspond." + assert procurement.move_dest_id.procure_method == order_line.type, "Procurement method is not correspond." - I run the scheduler. - From b1139e0affd5635e5592cf3ded77ad63a9a9c87a Mon Sep 17 00:00:00 2001 From: "Jitendra Prajapati (OpenERP)" Date: Thu, 22 Aug 2013 12:16:18 +0530 Subject: [PATCH 11/26] [IMP]improve rfq2order2done yml bzr revid: prajapatijitendra7969@gmail.com-20130822064618-l03lwozp4d6fth5p --- addons/purchase/test/process/rfq2order2done.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/purchase/test/process/rfq2order2done.yml b/addons/purchase/test/process/rfq2order2done.yml index 8a8dd946c92..a6999686026 100644 --- a/addons/purchase/test/process/rfq2order2done.yml +++ b/addons/purchase/test/process/rfq2order2done.yml @@ -46,9 +46,8 @@ Reception is ready for process so now done the reception. - !python {model: stock.picking}: | - pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_1")).picking_ids - self.do_prepare_partial(cr, uid, [pick_ids[0].id], context=context) - self.do_partial(cr, uid, [pick_ids[0].id], context=context) + pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_1")).picking_ids[0] + pick_ids.do_partial(context=context) - I check that purchase order is shipped. - From ee59841b3d895f04aece275e0a55387b3acb48b5 Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 22 Aug 2013 11:48:13 +0200 Subject: [PATCH 12/26] [WIP] Rereserve function for button + route_id on sales order line form view bzr revid: jco@openerp.com-20130822094813-jnvpa7rzsj6obr1p --- addons/sale/sale_view.xml | 1 + addons/stock/stock.py | 93 ++++++++++++++++++++++++++++++++++--- addons/stock/stock_view.xml | 2 +- 3 files changed, 88 insertions(+), 8 deletions(-) diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index 967350a88ac..bc7353b771f 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -397,6 +397,7 @@ + diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 357da1a3927..046ae6bff83 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -201,7 +201,6 @@ class stock_quant(osv.osv): else: self._quant_split(cr, uid, quant, qty, context=context) # FP Note: improve this using preferred locations - location_to = move.location_dest_id location_to = self.check_preferred_location(cr, uid, move, context=context) self.write(cr, uid, [quant.id], { 'location_id': location_to.id, @@ -239,7 +238,7 @@ class stock_quant(osv.osv): # Create a negative quant in the source location if it's an internal location # Reconcile a positive quant with a negative is possible # - def _quant_create(self, cr, uid, qty, move, context=None): + def _quant_create(self, cr, uid, qty, move, lot_id = False, context=None): # FP Note: TODO: compute the right price according to the move, with currency convert # QTY is normally already converted to main product's UoM price_unit = move.price_unit @@ -251,6 +250,7 @@ class stock_quant(osv.osv): 'history_ids': [(4, move.id)], 'in_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'company_id': move.company_id.id, + 'lot_id': lot_id, } negative_quant_id = False @@ -649,7 +649,7 @@ class stock_picking(osv.osv): 'cost': move.product_id.standard_price, }, context=context) - def _do_partial_product_move(self, cr, uid, picking, product, qty, quant=False, context=None): + def _do_partial_product_move(self, cr, uid, picking, product, qty, pack_id = False, lot_id = False, quant=False, context=None): moves = [] stock_move_obj = self.pool.get('stock.move') for move in picking.move_lines: @@ -684,6 +684,66 @@ class stock_picking(osv.osv): moves.append(move) return moves + def rereserve(self, cr, uid, picking_ids, create=False, context=None): + """ + This will unreserve all products and reserve the quants from the operations + """ + quant_obj = self.pool.get("stock.quant") + move_obj = self.pool.get("stock.move") + op_obj = self.pool.get("stock.pack.operation") + for picking in self.browse(cr, uid, picking_ids, context=context): + # unreserve everything + for move in picking.move_lines: + quant_obj.quants_unreserve(cr, uid, move, context=context) +# if picking.location_id.usage != 'internal' and picking.location_dest_id.usage == 'internal': #When to create the pickings? + ops_list = [(x.id, x.product_uom_qty) for x in picking.pack_operation_ids] + while ops_list: + ops = ops_list.pop() + #Find moves that correspond + if ops[0].product_id: + move_ids = move_obj.search(cr, uid, [('picking_id','=',picking.id), ('product_id', '=', ops[0].product_id), ('remaining_qty', '>', 0.0)], context=context) + for move in move_obj.browse(cr, uid, move_ids, context=context): + if move.remaining_qty > ops[1]: + qty = ops[1] + else: + qty = move.remaining_qty + # Add remaining quantity to the list + if ops[1] - qty > 0: + ops_list.append((ops[0] , ops[1] - qty),) + + if create and move.location_id != 'internal': + # Create quants + vals = { + 'product_id': move.product_id.id, + 'location_id': move.location_id.id, + 'qty': qty, + #'cost': price_unit, + 'history_ids': [(4, move.id)], + 'in_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), + 'company_id': move.company_id.id, + 'lot_id': ops[0].lot_id and ops.lot_id.id or False, + 'reservation_id': move.id, #Reserve at once + 'package_id': ops[0].result_package_id and ops[0].result_package_id.id or False, + } + quant_id = quant_obj.create(cr, uid, vals, context=context) + else: + #Quants get + domain = [('reservation_id', '=', False)] + prefered_order = op_obj._get_preferred_order(cr, uid, ops[0].id, context=context) + quants = quant_obj.quants_get(cr, uid, move.location_id, move.product_id, qty, domain=domain, prefered_order=prefered_order, context=context) + quant_obj.quants_reserve(cr, uid, quants, move, context=context) + elif ops[0].package_id: + lines = ops.package_id.quant_ids #_get_package_lines + to_reserve = [(x.id, x.product_uom_qty) for x in lines if not x.reservation_id] + quant_obj.quants_reserve(cr,uid, to_reserve, context=context) + #Need to check on which move +# for line in lines: +# if not line.reservation_id: +# quant_obj.quants_reserve(cr, uid, [(line.id, line.product_uom_qty)], context=context) + + + + def do_partial(self, cr, uid, picking_ids, context=None): """ If no pack operation, we close the whole move @@ -699,21 +759,19 @@ class stock_picking(osv.osv): for op in picking.pack_operation_ids: #TODO: op.package_id can not work as quants_get is not defined on quant package => gives traceback if op.package_id: - for quant in quant_package_obj.quants_get(cr, uid, op.package_id, context=context): + for quant in quant_package_obj.browse(cr, uid, op.package_id.id, context=context).quant_ids: self._do_partial_product_move(cr, uid, picking, quant.product_id, quant.qty, quant, context=context) op.package_id.write(cr, uid, { 'parent_id': op.result_package_id.id }, context=context) elif op.product_id: moves = self._do_partial_product_move(cr, uid, picking, op.product_id, op.product_qty, op.quant_id, context=context) - quants = [] for m in moves: for quant in m.quant_ids: quants.append(quant.id) quant_obj.write(cr, uid, quants, { 'package_id': op.result_package_id.id - }, context=context) self._create_backorder(cr, uid, picking, context=context) @@ -899,6 +957,8 @@ class stock_move(osv.osv): res[move.id] -= self.pool.get('stock.quant.package')._get_product_total_qty(cr, uid, op.package_id, move.product_id.id, context=context) return res + + def _get_lot_ids(self, cr, uid, ids, field_name, args, context=None): res = dict.fromkeys(ids, False) for move in self.browse(cr, uid, ids, context=context): @@ -1352,7 +1412,13 @@ class stock_move(osv.osv): # quant_obj.quants_move(cr, uid, quants, move, location_dest_id, context=context) # should replace the above 2 lines domain = ['|', ('reservation_id', '=', False), ('reservation_id', '=', move.id)] - quants = quant_obj.quants_get(cr, uid, move.location_id, move.product_id, qty, domain=domain, prefered_order = 'reservation_id<>'+str(move.id), context=context) + prefered_order = 'reservation_id<>' + str(move.id) +# if lot_id: +# prefered_order = 'lot_id<>' + lot_id + ", " + prefered_order +# if pack_id: +# prefered_order = 'pack_id<>' + pack_id + ", " + prefered_order + quants = quant_obj.quants_get(cr, uid, move.location_id, move.product_id, qty, domain=domain, prefered_order = prefered_order, context=context) + #Will move all quants_get and as such create negative quants quant_obj.quants_move(cr, uid, quants, move, context=context) quant_obj.quants_unreserve(cr, uid, move, context=context) @@ -1944,6 +2010,19 @@ class stock_pack_operation(osv.osv): 'date': fields.date.context_today, } + def _get_preferred_order(self, cr, uid, id, context=None): + pack = self.browse(cr, uid, id, context=context) + res = "" + if pack.package_id: + res += "package_id <> " + pack.package_id.id + if pack.lot_id: + if res: + res += ", lot_id <> " + pack.lot_id.id + else: + res += "lot_id <> " + pack.lot_id.id + return res + + #TODO: this function can be refactored def _search_and_increment(self, cr, uid, picking_id, key, context=None): '''Search for an operation on an existing key in a picking, if it exists increment the qty (+1) otherwise create it diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index 575712ad771..f6a8c12976c 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -803,7 +803,7 @@ - + From 9e15fb27b6e2beda17d7f164e0b6999d07e6cd2a Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 22 Aug 2013 14:21:03 +0200 Subject: [PATCH 13/26] [WIP] rereserve + store on remaining qty in move + remove route_id bzr revid: jco@openerp.com-20130822122103-a4qgvukgho8vuwv9 --- addons/sale/sale_view.xml | 1 - .../sale_stock_location_view.xml | 14 +++++++ addons/stock/stock.py | 39 ++++++++++++------- .../test/stock_invoice_directly.yml | 2 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index bc7353b771f..967350a88ac 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -397,7 +397,6 @@ - diff --git a/addons/sale_stock_location/sale_stock_location_view.xml b/addons/sale_stock_location/sale_stock_location_view.xml index 3d59828424c..2273831dce2 100644 --- a/addons/sale_stock_location/sale_stock_location_view.xml +++ b/addons/sale_stock_location/sale_stock_location_view.xml @@ -14,6 +14,20 @@ + + + sale.order.line.form.sale.stock.location.open + sale.order.line + + + + + + + + + + sale.order.line.tree.sale.stock.location diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 046ae6bff83..5a8e2641eff 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -697,19 +697,19 @@ class stock_picking(osv.osv): quant_obj.quants_unreserve(cr, uid, move, context=context) # if picking.location_id.usage != 'internal' and picking.location_dest_id.usage == 'internal': #When to create the pickings? ops_list = [(x.id, x.product_uom_qty) for x in picking.pack_operation_ids] - while ops_list: - ops = ops_list.pop() + for ops in picking.pack_operation_ids: #Find moves that correspond - if ops[0].product_id: - move_ids = move_obj.search(cr, uid, [('picking_id','=',picking.id), ('product_id', '=', ops[0].product_id), ('remaining_qty', '>', 0.0)], context=context) - for move in move_obj.browse(cr, uid, move_ids, context=context): - if move.remaining_qty > ops[1]: - qty = ops[1] + if ops.product_id: + move_ids = move_obj.search(cr, uid, [('picking_id','=',picking.id), ('product_id', '=', ops.product_id), ('remaining_qty', '>', 0.0)], context=context) + qty_to_do = ops.product_uom_qty + while qty_to_do > 0 and move_ids: + move = move_obj.browse(cr, uid, move_ids.pop(), context=context) + if move.remaining_qty > qty_to_do: + qty = qty_to_do + qty_to_do = 0 else: qty = move.remaining_qty - # Add remaining quantity to the list - if ops[1] - qty > 0: - ops_list.append((ops[0] , ops[1] - qty),) + qty_to_do -= move.remaining_qty if create and move.location_id != 'internal': # Create quants @@ -733,9 +733,12 @@ class stock_picking(osv.osv): quants = quant_obj.quants_get(cr, uid, move.location_id, move.product_id, qty, domain=domain, prefered_order=prefered_order, context=context) quant_obj.quants_reserve(cr, uid, quants, move, context=context) elif ops[0].package_id: - lines = ops.package_id.quant_ids #_get_package_lines + lines = ops[0].package_id.quant_ids #_get_package_lines to_reserve = [(x.id, x.product_uom_qty) for x in lines if not x.reservation_id] - quant_obj.quants_reserve(cr,uid, to_reserve, context=context) + for reserve in to_reserve: + move_ids = move_obj.search(cr, uid, [('picking_id', '=', picking.id), ('product_id', '=', reserve.product_id)]) + quant_obj.quants_reserve(cr, uid, to_reserve, context=context) + #Need to check on which move # for line in lines: # if not line.reservation_id: @@ -983,6 +986,14 @@ class stock_move(osv.osv): res[move.id] = min(move.product_qty, availability) return res + + def _get_move(self, cr, uid, ids, context=None): + res = set() + for quant in self.browse(cr, uid, ids, context=context): + if quant.reservation_id: + res.add(quant.reservation_id.id) + return list(res) + _columns = { 'name': fields.char('Description', required=True, select=True), 'priority': fields.selection([('0', 'Not urgent'), ('1', 'Urgent')], 'Priority'), @@ -1048,7 +1059,9 @@ class stock_move(osv.osv): 'quant_ids': fields.many2many('stock.quant', 'stock_quant_move_rel', 'move_id', 'quant_id', 'Quants'), 'reserved_quant_ids': fields.one2many('stock.quant', 'reservation_id', 'Reserved quants'), - 'remaining_qty': fields.function(_get_remaining_qty, type='float', string='Remaining Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), states={'done': [('readonly', True)]}), + 'remaining_qty': fields.function(_get_remaining_qty, type='float', string='Remaining Quantity', + digits_compute=dp.get_precision('Product Unit of Measure'), states={'done': [('readonly', True)]}, + store = {'stock.quant': (_get_move, ['reservation_id'], 10)}), 'procurement_id': fields.many2one('procurement.order', 'Procurement'), 'group_id': fields.related('procurement_id', 'group_id', type='many2one', relation="procurement.group", string='Procurement Group'), 'rule_id': fields.many2one('procurement.rule', 'Procurement Rule'), diff --git a/addons/stock_invoice_directly/test/stock_invoice_directly.yml b/addons/stock_invoice_directly/test/stock_invoice_directly.yml index 53ecee5be8d..5e2daaccf4f 100644 --- a/addons/stock_invoice_directly/test/stock_invoice_directly.yml +++ b/addons/stock_invoice_directly/test/stock_invoice_directly.yml @@ -15,7 +15,7 @@ product_uom: product.product_uom_unit location_dest_id: stock.stock_location_customers move_type: direct - type: out + picking_type_id: stock.picking_type_out - I need to check the availability of the product so I make my picking order for processing later. - From 67bcf36f137c2834965f9b55350db174b7c96b04 Mon Sep 17 00:00:00 2001 From: "Randhir Mayatra (OpenERP)" Date: Thu, 22 Aug 2013 18:21:50 +0530 Subject: [PATCH 14/26] [IMP] place lifo_price yml into complex_routs and make changes bzr revid: rma@tinyerp.com-20130822125150-zdj1lo96axkwor0e --- addons/purchase/__openerp__.py | 28 +++++++------- addons/stock_complex_routes/__openerp__.py | 2 +- .../test/lifo_price.yml | 37 +++++++++++-------- 3 files changed, 37 insertions(+), 30 deletions(-) rename addons/{purchase => stock_complex_routes}/test/lifo_price.yml (76%) diff --git a/addons/purchase/__openerp__.py b/addons/purchase/__openerp__.py index 56512be09da..36df07a95bd 100644 --- a/addons/purchase/__openerp__.py +++ b/addons/purchase/__openerp__.py @@ -67,20 +67,20 @@ Dashboard / Reports for Purchase Management will include: 'res_config_view.xml', ], 'test': [ - 'test/fifo_price.yml', - 'test/fifo_returns.yml', - #'test/costmethodchange.yml', - 'test/process/cancel_order.yml', - 'test/process/rfq2order2done.yml', - 'test/process/generate_invoice_from_reception.yml', - 'test/process/run_scheduler.yml', - 'test/process/merge_order.yml', - 'test/process/edi_purchase_order.yml', - 'test/process/invoice_on_poline.yml', - 'test/ui/print_report.yml', - 'test/ui/duplicate_order.yml', - 'test/ui/delete_order.yml', - 'test/average_price.yml', +# 'test/fifo_price.yml', +# 'test/fifo_returns.yml', +# #'test/costmethodchange.yml', +# 'test/process/cancel_order.yml', +# 'test/process/rfq2order2done.yml', +# 'test/process/generate_invoice_from_reception.yml', +# 'test/process/run_scheduler.yml', +# 'test/process/merge_order.yml', +# 'test/process/edi_purchase_order.yml', +# 'test/process/invoice_on_poline.yml', +# 'test/ui/print_report.yml', +# 'test/ui/duplicate_order.yml', +# 'test/ui/delete_order.yml', +# 'test/average_price.yml', 'test/lifo_price.yml', ], 'demo': [ diff --git a/addons/stock_complex_routes/__openerp__.py b/addons/stock_complex_routes/__openerp__.py index 5426e2c7aca..c9bdff7c7a8 100644 --- a/addons/stock_complex_routes/__openerp__.py +++ b/addons/stock_complex_routes/__openerp__.py @@ -38,7 +38,7 @@ This adds a route on the sales order and sales order line (mini module) 'init_xml': [], 'update_xml': ['stock_complex_routes.xml'], 'demo_xml': [], - 'test': [], + 'test': ['lifo_price.yml'], 'installable': True, 'auto_install': True, } diff --git a/addons/purchase/test/lifo_price.yml b/addons/stock_complex_routes/test/lifo_price.yml similarity index 76% rename from addons/purchase/test/lifo_price.yml rename to addons/stock_complex_routes/test/lifo_price.yml index ea30317b996..5c3aa5bb3b6 100644 --- a/addons/purchase/test/lifo_price.yml +++ b/addons/stock_complex_routes/test/lifo_price.yml @@ -1,8 +1,15 @@ +- + For check product removal create removal strategy "LIFO" +- + !record {model: product.removal, id: product_removal_lifo}: + product_categ_id: product.product_category_1 + method: lifo + location_id: stock.stock_location_stock - - Set product category removal strategy as LIFO + Set product category removal strategy as LIFO - !record {model: product.category, id: product.product_category_1}: - removal_strategy: lifo + removal_strategy_ids: product_removal_lifo - Set a product as using lifo price - @@ -58,10 +65,9 @@ - Process the reception of purchase order 1 - - !python {model: stock.partial.picking}: | - pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lifo1")).picking_ids - partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]}) - self.do_partial(cr, uid, [partial_id]) + !python {model: stock.picking}: | + order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lifo1")).picking_ids[0] + order.do_partial(context=context) - Check the standard price of the product (lifo icecream) - @@ -74,10 +80,9 @@ - Process the reception of purchase order 2 - - !python {model: stock.partial.picking}: | - pick_ids = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lifo2")).picking_ids - partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [pick_ids[0].id]}) - self.do_partial(cr, uid, [partial_id]) + !python {model: stock.picking}: | + order = self.pool.get('purchase.order').browse(cr, uid, ref("purchase_order_lifo2")).picking_ids[0] + order.do_partial(context=context) - Check the standard price should not have changed - @@ -87,7 +92,7 @@ Let us send some goods - !record {model: stock.picking, id: outgoing_lifo_shipment}: - type: out + picking_type_id: stock.picking_type_out - Picking needs movement from stock - @@ -95,8 +100,10 @@ picking_id: outgoing_lifo_shipment product_id: product_lifo_icecream product_uom: product.product_uom_kgm + location_id: stock.stock_location_stock + location_dest_id: stock.stock_location_customers product_qty: 20.0 - type: out + picking_type_id: stock.picking_type_out - I assign this outgoing shipment - @@ -105,9 +112,9 @@ - Process the delivery of the outgoing shipment - - !python {model: stock.partial.picking}: | - partial_id = self.create(cr, uid, {}, context={'active_model': 'stock.picking','active_ids': [ref("outgoing_lifo_shipment")], 'default_type':'out'}) - self.do_partial(cr, uid, [partial_id]) + !python {model: stock.picking}: | + pick_order = self.pool.get('stock.picking').browse(cr, uid, ref("outgoing_lifo_shipment")) + pick_order.do_partial(context=context) - Check standard price became 80 euro - From 9690f9070a91dbf97095e9eff1c1accef1070b7e Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Thu, 22 Aug 2013 16:49:44 +0200 Subject: [PATCH 15/26] [WIP] Rereserve button with qty remaining and should return ops remaining, adjust packing.yml, revert salestock view bzr revid: jco@openerp.com-20130822144944-2bhuyziu7dk1asio --- .../sale_stock_location_view.xml | 13 ---- addons/stock/stock.py | 75 ++++++++++++------- addons/stock/stock_view.xml | 1 + addons/stock/test/packing.yml | 64 ++++++++++++++-- 4 files changed, 105 insertions(+), 48 deletions(-) diff --git a/addons/sale_stock_location/sale_stock_location_view.xml b/addons/sale_stock_location/sale_stock_location_view.xml index 2273831dce2..0a8ad68f060 100644 --- a/addons/sale_stock_location/sale_stock_location_view.xml +++ b/addons/sale_stock_location/sale_stock_location_view.xml @@ -15,19 +15,6 @@ - - sale.order.line.form.sale.stock.location.open - sale.order.line - - - - - - - - - - sale.order.line.tree.sale.stock.location diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 5a8e2641eff..73a0f2ab4c0 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -687,21 +687,21 @@ class stock_picking(osv.osv): def rereserve(self, cr, uid, picking_ids, create=False, context=None): """ This will unreserve all products and reserve the quants from the operations + :return: dictionary with quantities of quant operation and product that can not be matched with moves """ quant_obj = self.pool.get("stock.quant") move_obj = self.pool.get("stock.move") op_obj = self.pool.get("stock.pack.operation") + res = {} for picking in self.browse(cr, uid, picking_ids, context=context): # unreserve everything for move in picking.move_lines: quant_obj.quants_unreserve(cr, uid, move, context=context) -# if picking.location_id.usage != 'internal' and picking.location_dest_id.usage == 'internal': #When to create the pickings? - ops_list = [(x.id, x.product_uom_qty) for x in picking.pack_operation_ids] for ops in picking.pack_operation_ids: #Find moves that correspond if ops.product_id: - move_ids = move_obj.search(cr, uid, [('picking_id','=',picking.id), ('product_id', '=', ops.product_id), ('remaining_qty', '>', 0.0)], context=context) - qty_to_do = ops.product_uom_qty + move_ids = move_obj.search(cr, uid, [('picking_id','=',picking.id), ('product_id', '=', ops.product_id.id), ('remaining_qty', '>', 0.0)], context=context) + qty_to_do = ops.product_qty while qty_to_do > 0 and move_ids: move = move_obj.browse(cr, uid, move_ids.pop(), context=context) if move.remaining_qty > qty_to_do: @@ -721,24 +721,35 @@ class stock_picking(osv.osv): 'history_ids': [(4, move.id)], 'in_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S'), 'company_id': move.company_id.id, - 'lot_id': ops[0].lot_id and ops.lot_id.id or False, + 'lot_id': ops.lot_id and ops.lot_id.id or False, 'reservation_id': move.id, #Reserve at once - 'package_id': ops[0].result_package_id and ops[0].result_package_id.id or False, + 'package_id': ops.result_package_id and ops.result_package_id.id or False, } quant_id = quant_obj.create(cr, uid, vals, context=context) else: #Quants get domain = [('reservation_id', '=', False)] - prefered_order = op_obj._get_preferred_order(cr, uid, ops[0].id, context=context) + prefered_order = op_obj._get_preferred_order(cr, uid, ops.id, context=context) quants = quant_obj.quants_get(cr, uid, move.location_id, move.product_id, qty, domain=domain, prefered_order=prefered_order, context=context) quant_obj.quants_reserve(cr, uid, quants, move, context=context) - elif ops[0].package_id: - lines = ops[0].package_id.quant_ids #_get_package_lines - to_reserve = [(x.id, x.product_uom_qty) for x in lines if not x.reservation_id] - for reserve in to_reserve: - move_ids = move_obj.search(cr, uid, [('picking_id', '=', picking.id), ('product_id', '=', reserve.product_id)]) - quant_obj.quants_reserve(cr, uid, to_reserve, context=context) - + res[ops.id] = {} + res[ops.id][ops.product_id.id] = qty_to_do + elif ops.package_id: + quants = ops.package_id.quant_ids #_get_package_lines + for quant in quants: + move_ids = move_obj.search(cr, uid, [('picking_id', '=', picking.id), ('product_id', '=', quant.product_id.id), ('remaining_qty', '>', 0.0)]) + qty_to_do = quant.qty + while qty_to_do > 0 and move_ids: + move = move_obj.browse(cr, uid, move_ids.pop(), context=context) + if move.remaining_qty > qty_to_do: + qty = qty_to_do + qty_to_do = 0 + else: + qty = move.remaining_qty + qty_to_do -= move.remaining_qty + quant_obj.quants_reserve(cr, uid, [(quant.id, qty)], move, context=context) + + #quant_obj.quants_reserve(cr, uid, to_reserve, context=context) #Need to check on which move # for line in lines: # if not line.reservation_id: @@ -945,21 +956,29 @@ class stock_move(osv.osv): res[m.id] = uom_obj._compute_qty_obj(cr, uid, m.product_uom, m.product_uom_qty, m.product_id.uom_id) return res - def _get_remaining_qty(self, cr, uid, ids, field_name, args, context=None): - #TODO: this function assumes that there aren't several stock move in the same picking with the same product. what should we do in that case? - #TODO take care of the quant on stock moves too - res = dict.fromkeys(ids, False) - for move in self.browse(cr, uid, ids, context=context): - res[move.id] = move.product_qty - if move.picking_id: - for op in move.picking_id.pack_operation_ids: - if op.product_id == move.product_id or (op.quant_id and op.quant_id.product_id == move.product_id): - res[move.id] -= op.product_qty - if op.package_id: - #find the product qty recursively - res[move.id] -= self.pool.get('stock.quant.package')._get_product_total_qty(cr, uid, op.package_id, move.product_id.id, context=context) - return res +# def _get_remaining_qty(self, cr, uid, ids, field_name, args, context=None): +# #TODO: this function assumes that there aren't several stock move in the same picking with the same product. what should we do in that case? +# #TODO take care of the quant on stock moves too +# res = dict.fromkeys(ids, False) +# for move in self.browse(cr, uid, ids, context=context): +# res[move.id] = move.product_qty +# if move.picking_id: +# for op in move.picking_id.pack_operation_ids: +# if op.product_id == move.product_id or (op.quant_id and op.quant_id.product_id == move.product_id): +# res[move.id] -= op.product_qty +# if op.package_id: +# #find the product qty recursively +# res[move.id] -= self.pool.get('stock.quant.package')._get_product_total_qty(cr, uid, op.package_id, move.product_id.id, context=context) +# return res + def _get_remaining_qty(self, cr, uid, ids, field_name, args, context=None): + res = {} + for move in self.browse(cr, uid, ids, context=context): + res[move.id] = move.product_uom_qty + for quant in move.reserved_quant_ids: + res[move.id] -= quant.qty + return res + def _get_lot_ids(self, cr, uid, ids, field_name, args, context=None): diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index f6a8c12976c..c0c6ba97976 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -583,6 +583,7 @@