Skip to content

Commit

Permalink
[MIG] sale_manual_delivery: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rdualsam committed Jan 9, 2025
1 parent 40a4b00 commit 55f8d8e
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 57 deletions.
4 changes: 2 additions & 2 deletions sale_manual_delivery/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions sale_manual_delivery/hook.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion sale_manual_delivery/models/crm_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
1 change: 0 additions & 1 deletion sale_manual_delivery/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
3 changes: 2 additions & 1 deletion sale_manual_delivery/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 1 addition & 19 deletions sale_manual_delivery/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 += [
Expand Down
4 changes: 2 additions & 2 deletions sale_manual_delivery/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
19 changes: 5 additions & 14 deletions sale_manual_delivery/tests/test_manual_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,7 +56,6 @@ def test_00_sale_manual_delivery(self):
},
)
],
"pricelist_id": self.env.ref("product.list0").id,
"manual_delivery": True,
}
)
Expand Down Expand Up @@ -110,7 +109,6 @@ def test_01_sale_standard_delivery(self):
},
)
],
"pricelist_id": self.env.ref("product.list0").id,
"manual_delivery": False,
}
)
Expand All @@ -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)
Expand Down Expand Up @@ -151,7 +149,6 @@ def test_02_sale_various_manual_delivery(self):
},
)
],
"pricelist_id": self.env.ref("product.list0").id,
"manual_delivery": True,
}
)
Expand All @@ -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)
Expand Down Expand Up @@ -229,7 +226,6 @@ def test_03_sale_selected_lines(self):
},
)
],
"pricelist_id": self.env.ref("product.list0").id,
"manual_delivery": True,
}
)
Expand All @@ -251,7 +247,6 @@ def test_03_sale_selected_lines(self):
},
)
],
"pricelist_id": self.env.ref("product.list0").id,
"manual_delivery": True,
}
)
Expand All @@ -273,7 +268,6 @@ def test_03_sale_selected_lines(self):
},
)
],
"pricelist_id": self.env.ref("product.list0").id,
"manual_delivery": True,
}
)
Expand All @@ -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",
)
Expand Down Expand Up @@ -348,7 +342,6 @@ def test_03_sale_multi_delivery(self):
},
),
],
"pricelist_id": self.env.ref("product.list0").id,
"manual_delivery": True,
}
)
Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -453,7 +446,6 @@ def test_04_sale_single_picking(self):
},
),
],
"pricelist_id": self.env.ref("product.list0").id,
"manual_delivery": True,
}
)
Expand Down Expand Up @@ -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,
}
Expand Down
6 changes: 3 additions & 3 deletions sale_manual_delivery/views/sale_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
/>
</button>
<group name="sale_shipping" position="inside">
Expand All @@ -22,7 +22,7 @@
</field>
</record>
<record id="view_order_line_tree" model="ir.ui.view">
<field name="name">sale.order.line.tree</field>
<field name="name">sale.order.line.list</field>
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_order_line_tree" />
<field name="arch" type="xml">
Expand Down Expand Up @@ -52,7 +52,7 @@
<field name="name">Sale Lines to Deliver</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">sale.order.line</field>
<field name="view_mode">tree</field>
<field name="view_mode">list</field>
<field name="search_view_id" ref="view_sales_order_undelivered_line_filter" />
<field name="context">{"search_default_filter_unplanned":1}</field>
<field name="filter" eval="True" />
Expand Down
12 changes: 4 additions & 8 deletions sale_manual_delivery/wizard/manual_delivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"""
Expand Down
4 changes: 2 additions & 2 deletions sale_manual_delivery/wizard/manual_delivery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
</group>
</group>
<field name='line_ids'>
<tree editable="bottom" create="0">
<list editable="bottom" create="0">
<field name="order_line_id" invisible="1" force_save="1" />
<field name="product_id" />
<field name="name" />
<field name="qty_ordered" string="Ordered" />
<field name="qty_procured" string="Procured" />
<field name="quantity" />
</tree>
</list>
</field>
</sheet>
<footer>
Expand Down

0 comments on commit 55f8d8e

Please sign in to comment.