diff --git a/sale_manual_delivery/__manifest__.py b/sale_manual_delivery/__manifest__.py index e7bb9a92dee0..266d2f302e06 100644 --- a/sale_manual_delivery/__manifest__.py +++ b/sale_manual_delivery/__manifest__.py @@ -5,10 +5,10 @@ "category": "Sale", "author": "Camptocamp SA, Odoo Community Association (OCA)", "license": "AGPL-3", - "version": "14.0.1.0.0", + "version": "18.0.1.0.0", "website": "https://github.com/OCA/sale-workflow", "summary": "Create manually your deliveries", - "depends": ["delivery", "sale_stock", "sales_team"], + "depends": ["stock_delivery", "sale_stock", "sales_team"], "data": [ "security/ir.model.access.csv", "views/crm_team.xml", diff --git a/sale_manual_delivery/hook.py b/sale_manual_delivery/hook.py index a2f58d769dcf..3742cb6a20a0 100644 --- a/sale_manual_delivery/hook.py +++ b/sale_manual_delivery/hook.py @@ -1,18 +1,18 @@ -def pre_init_hook(cr): - cr.execute( +def pre_init_hook(env): + env.cr.execute( """ ALTER TABLE sale_order_line ADD COLUMN IF NOT EXISTS qty_procured numeric; COMMENT ON COLUMN sale_order_line.qty_procured IS 'Quantity Procured'; """ ) - cr.execute( + env.cr.execute( """ ALTER TABLE sale_order_line ADD COLUMN IF NOT EXISTS qty_to_procure numeric; COMMENT ON COLUMN sale_order_line.qty_to_procure IS 'Quantity to Procure"'; """ ) - cr.execute( + env.cr.execute( """ update sale_order_line as sol set qty_procured = r.qty_procured, qty_to_procure = sol.product_uom_qty - r.qty_procured diff --git a/sale_manual_delivery/models/crm_team.py b/sale_manual_delivery/models/crm_team.py index 5bdd16a76430..fbf46bbc1ac7 100644 --- a/sale_manual_delivery/models/crm_team.py +++ b/sale_manual_delivery/models/crm_team.py @@ -8,7 +8,6 @@ class CrmTeam(models.Model): _inherit = "crm.team" manual_delivery = fields.Boolean( - string="Manual Delivery", help="If enabled, the deliveries are not created at SO confirmation. " "You need to use the Create Delivery button in order to reserve and " "ship the goods.", diff --git a/sale_manual_delivery/models/sale_order.py b/sale_manual_delivery/models/sale_order.py index d4079abcc00e..776731e248b4 100644 --- a/sale_manual_delivery/models/sale_order.py +++ b/sale_manual_delivery/models/sale_order.py @@ -10,7 +10,6 @@ class SaleOrder(models.Model): _inherit = "sale.order" manual_delivery = fields.Boolean( - string="Manual Delivery", default=False, help="If enabled, the deliveries are not created at SO confirmation. " "You need to use the Create Delivery button in order to reserve " diff --git a/sale_manual_delivery/models/sale_order_line.py b/sale_manual_delivery/models/sale_order_line.py index c84ffb4fda24..83a5c48d6332 100644 --- a/sale_manual_delivery/models/sale_order_line.py +++ b/sale_manual_delivery/models/sale_order_line.py @@ -100,7 +100,8 @@ def _action_launch_stock_rule_manual(self, previous_product_uom_qty=False): # Qty comes from the manual delivery wizard # This is different than the original method manual_line = manual_delivery.line_ids.filtered( - lambda l: l.order_line_id == line + lambda manual_delivery_line, + sol=line: manual_delivery_line.order_line_id == sol ) if not manual_line.quantity: continue diff --git a/sale_manual_delivery/models/stock_move.py b/sale_manual_delivery/models/stock_move.py index 4af93387df8b..f59a8c01f92f 100644 --- a/sale_manual_delivery/models/stock_move.py +++ b/sale_manual_delivery/models/stock_move.py @@ -26,25 +26,7 @@ def _search_picking_for_assignation(self): manual_delivery = self.env.context.get("sale_manual_delivery") if manual_delivery: # original domain used in super() - domain = [ - ("group_id", "=", self.group_id.id), - ("location_id", "=", self.location_id.id), - ("location_dest_id", "=", self.location_dest_id.id), - ("picking_type_id", "=", self.picking_type_id.id), - ("printed", "=", False), - ("immediate_transfer", "=", False), - ( - "state", - "in", - [ - "draft", - "confirmed", - "waiting", - "partially_available", - "assigned", - ], - ), - ] + domain = self._search_picking_for_assignation_domain() # Filter on carrier if manual_delivery.carrier_id: domain += [ diff --git a/sale_manual_delivery/security/ir.model.access.csv b/sale_manual_delivery/security/ir.model.access.csv index 44767e73c418..7ee6261b4807 100644 --- a/sale_manual_delivery/security/ir.model.access.csv +++ b/sale_manual_delivery/security/ir.model.access.csv @@ -1,3 +1,3 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_manual_delivery_all,access_manual_delivery_all,model_manual_delivery,,1,1,1,1 -access_manual_delivery_line_all,access_manual_delivery_line_all,model_manual_delivery_line,,1,1,1,1 +access_manual_delivery_all,access_manual_delivery_all,model_manual_delivery,stock.group_stock_user,1,1,1,1 +access_manual_delivery_line_all,access_manual_delivery_line_all,model_manual_delivery_line,stock.group_stock_user,1,1,1,1 diff --git a/sale_manual_delivery/tests/test_manual_delivery.py b/sale_manual_delivery/tests/test_manual_delivery.py index 4ac53b4c4f1b..17c8b9334d64 100644 --- a/sale_manual_delivery/tests/test_manual_delivery.py +++ b/sale_manual_delivery/tests/test_manual_delivery.py @@ -16,7 +16,7 @@ def setUp(self): self.product2 = self.env.ref("product.product_delivery_02") self.product3 = self.env.ref("product.product_order_01") self.carrier1 = self.env.ref("delivery.delivery_carrier") - self.carrier2 = self.env.ref("delivery.normal_delivery_carrier") + self.carrier2 = self.env.ref("delivery.delivery_local_delivery") self.stock_location = self.env.ref("stock.stock_location_stock") self.env["stock.quant"]._update_available_quantity( self.product, self.stock_location, 100 @@ -56,7 +56,6 @@ def test_00_sale_manual_delivery(self): }, ) ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": True, } ) @@ -110,7 +109,6 @@ def test_01_sale_standard_delivery(self): }, ) ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": False, } ) @@ -123,7 +121,7 @@ def test_01_sale_standard_delivery(self): # deliver completely pick = order.picking_ids pick.action_assign() - pick.move_line_ids.write({"qty_done": 5}) + pick.move_line_ids.write({"quantity": 5}) pick.button_validate() # Check quantity delivered del_qty = sum(sol.qty_delivered for sol in order.order_line) @@ -151,7 +149,6 @@ def test_02_sale_various_manual_delivery(self): }, ) ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": True, } ) @@ -176,7 +173,7 @@ def test_02_sale_various_manual_delivery(self): # deliver completely pick = order.picking_ids pick.action_assign() - pick.move_line_ids.write({"qty_done": 2}) + pick.move_line_ids.write({"quantity": 2}) pick.button_validate() # Check quantity delivered del_qty = sum(sol.qty_delivered for sol in order.order_line) @@ -229,7 +226,6 @@ def test_03_sale_selected_lines(self): }, ) ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": True, } ) @@ -251,7 +247,6 @@ def test_03_sale_selected_lines(self): }, ) ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": True, } ) @@ -273,7 +268,6 @@ def test_03_sale_selected_lines(self): }, ) ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": True, } ) @@ -293,7 +287,7 @@ def test_03_sale_selected_lines(self): 'Picking should be created after "manual delivery" wizard call', ) self.assertEqual( - len(order3.picking_ids.move_lines), + len(order3.picking_ids.move_ids), 1, "Different sales orders should still create different pickings", ) @@ -348,7 +342,6 @@ def test_03_sale_multi_delivery(self): }, ), ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": True, } ) @@ -416,7 +409,7 @@ def test_03_sale_multi_delivery(self): ' after "manual delivery" wizard call with same date', ) self.assertEqual( - sum(first_picking.mapped("move_lines.product_uom_qty")), + sum(first_picking.mapped("move_ids.product_uom_qty")), 7, ) @@ -453,7 +446,6 @@ def test_04_sale_single_picking(self): }, ), ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": True, } ) @@ -485,7 +477,6 @@ def test_05_sale_multi_carrier(self): }, ), ], - "pricelist_id": self.env.ref("product.list0").id, "manual_delivery": True, "carrier_id": self.carrier1.id, } diff --git a/sale_manual_delivery/views/sale_order.xml b/sale_manual_delivery/views/sale_order.xml index 2cfa20f6f8db..791e7dd3e811 100644 --- a/sale_manual_delivery/views/sale_order.xml +++ b/sale_manual_delivery/views/sale_order.xml @@ -12,7 +12,7 @@ class="btn btn-primary" string="Create Delivery" context="{'active_model': 'sale.order', 'active_id': id, 'active_ids': [id]}" - attrs="{'invisible': ['|', '|', ('has_pending_delivery', '=', False), ('manual_delivery', '=', False), ('state', '!=', 'sale')]}" + invisible="not has_pending_delivery or not manual_delivery or state != 'sale'" /> @@ -22,7 +22,7 @@ - sale.order.line.tree + sale.order.line.list sale.order.line @@ -52,7 +52,7 @@ Sale Lines to Deliver ir.actions.act_window sale.order.line - tree + list {"search_default_filter_unplanned":1} diff --git a/sale_manual_delivery/wizard/manual_delivery.py b/sale_manual_delivery/wizard/manual_delivery.py index 51dc52d18015..9fce1e97634f 100644 --- a/sale_manual_delivery/wizard/manual_delivery.py +++ b/sale_manual_delivery/wizard/manual_delivery.py @@ -58,13 +58,9 @@ def default_get(self, fields): partner_id = fields.Many2one( "res.partner", string="Delivery Address", - domain=""" - [ - "|", - ("id", "=", commercial_partner_id), - ("parent_id", "=", commercial_partner_id), - ], - """, + domain="['|'," + "('id', '=', commercial_partner_id)," + "('parent_id', '=', commercial_partner_id)]", ondelete="cascade", ) carrier_id = fields.Many2one( @@ -84,7 +80,7 @@ def default_get(self, fields): "manual_delivery_id", string="Lines to validate", ) - date_planned = fields.Datetime(string="Date Planned") + date_planned = fields.Datetime() def confirm(self): """Creates the manual procurements""" diff --git a/sale_manual_delivery/wizard/manual_delivery.xml b/sale_manual_delivery/wizard/manual_delivery.xml index 59233d4511e1..76fc70f79f58 100644 --- a/sale_manual_delivery/wizard/manual_delivery.xml +++ b/sale_manual_delivery/wizard/manual_delivery.xml @@ -22,14 +22,14 @@ - + - +