Skip to content

Commit 68781a9

Browse files
[MIG] sale_blanket_order: Migration to 18.0
[MIG] sale_blanket_order: Migration to 18.0
1 parent c1c857c commit 68781a9

File tree

6 files changed

+55
-46
lines changed

6 files changed

+55
-46
lines changed

sale_blanket_order/models/blanket_orders.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2018 ACSONE SA/NV
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo import _, api, fields, models
4+
from odoo import api, fields, models
55
from odoo.exceptions import UserError
66
from odoo.tools import float_is_zero
77
from odoo.tools.misc import format_date
@@ -239,7 +239,7 @@ def unlink(self):
239239
for order in self:
240240
if order.state not in ("draft", "expired") or order._check_active_orders():
241241
raise UserError(
242-
_(
242+
self.env._(
243243
"You can not delete an open blanket or "
244244
"with active sale orders! "
245245
"Try to cancel it before."
@@ -251,12 +251,12 @@ def _validate(self):
251251
try:
252252
today = fields.Date.today()
253253
for order in self:
254-
assert order.validity_date, _("Validity date is mandatory")
255-
assert order.validity_date > today, _(
254+
assert order.validity_date, self.env._("Validity date is mandatory")
255+
assert order.validity_date > today, self.env._(
256256
"Validity date must be in the future"
257257
)
258-
assert order.partner_id, _("Partner is mandatory")
259-
assert len(order.line_ids) > 0, _("Must have some lines")
258+
assert order.partner_id, self.env._("Partner is mandatory")
259+
assert len(order.line_ids) > 0, self.env._("Must have some lines")
260260
order.line_ids._validate()
261261
except AssertionError as e:
262262
raise UserError(e) from e
@@ -287,7 +287,7 @@ def action_cancel(self):
287287
for order in self:
288288
if order._check_active_orders():
289289
raise UserError(
290-
_(
290+
self.env._(
291291
"You can not delete a blanket order with opened "
292292
"sale orders! "
293293
"Try to cancel them before."
@@ -481,9 +481,11 @@ def _compute_display_name(self):
481481
name = f"[{record.order_id.name}]"
482482
if record.date_schedule:
483483
formatted_date = format_date(record.env, record.date_schedule)
484-
name += " - {}: {}".format(_("Date Scheduled"), formatted_date)
484+
name += " - {}: {}".format(
485+
self.env._("Date Scheduled"), formatted_date
486+
)
485487
name += " ({}: {} {})".format(
486-
_("remaining"),
488+
self.env._("remaining"),
487489
record.remaining_uom_qty,
488490
record.product_uom.name,
489491
)
@@ -506,12 +508,11 @@ def _get_real_price_currency(self, product, rule_id, qty, uom, pricelist_id):
506508
product_currency = None
507509
if rule_id:
508510
pricelist_item = PricelistItem.browse(rule_id)
509-
if pricelist_item.pricelist_id.discount_policy == "without_discount":
511+
if pricelist_item._show_discount():
510512
while (
511513
pricelist_item.base == "pricelist"
512514
and pricelist_item.base_pricelist_id
513-
and pricelist_item.base_pricelist_id.discount_policy
514-
== "without_discount"
515+
and pricelist_item._show_discount()
515516
):
516517
price, rule_id = pricelist_item.base_pricelist_id.with_context(
517518
uom=uom.id
@@ -668,10 +669,10 @@ def _validate(self):
668669
for line in self:
669670
assert (
670671
not line.display_type and line.price_unit > 0.0
671-
) or line.display_type, _("Price must be greater than zero")
672+
) or line.display_type, self.env._("Price must be greater than zero")
672673
assert (
673674
not line.display_type and line.original_uom_qty > 0.0
674-
) or line.display_type, _("Quantity must be greater than zero")
675+
) or line.display_type, self.env._("Quantity must be greater than zero")
675676
except AssertionError as e:
676677
raise UserError(e) from e
677678

@@ -715,7 +716,7 @@ def write(self, values):
715716
lambda line: line.display_type != values.get("display_type")
716717
):
717718
raise UserError(
718-
_(
719+
self.env._(
719720
"""
720721
You cannot change the type of a sale order line.
721722
Instead you should delete the current line and create a new line

sale_blanket_order/models/sale_orders.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44
from datetime import date, timedelta
55

6-
from odoo import _, api, fields, models
6+
from odoo import api, fields, models
77
from odoo.exceptions import ValidationError
88

99

@@ -30,7 +30,7 @@ def action_confirm(self):
3030
for order in self:
3131
if order._check_exchausted_blanket_order_line():
3232
raise ValidationError(
33-
_(
33+
self.env._(
3434
"Cannot confirm order %s as one of the lines refers "
3535
"to a blanket order that has no remaining quantity."
3636
)
@@ -44,7 +44,7 @@ def check_partner_id(self):
4444
if line.blanket_order_line:
4545
if line.blanket_order_line.partner_id != self.partner_id:
4646
raise ValidationError(
47-
_(
47+
self.env._(
4848
"The customer must be equal to the "
4949
"blanket order lines customer"
5050
)
@@ -179,7 +179,7 @@ def check_product_id(self):
179179
and line.product_id != line.blanket_order_line.product_id
180180
):
181181
raise ValidationError(
182-
_(
182+
self.env._(
183183
"The product in the blanket order and in the "
184184
"sales order must match"
185185
)
@@ -191,7 +191,7 @@ def check_currency(self):
191191
if line.blanket_order_line:
192192
if line.currency_id != line.blanket_order_line.order_id.currency_id:
193193
raise ValidationError(
194-
_(
194+
self.env._(
195195
"The currency of the blanket order must match with "
196196
"that of the sale order."
197197
)

sale_blanket_order/tests/test_blanket_orders.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ def setUpClass(cls):
1515
cls.blanket_order_line_obj = cls.env["sale.blanket.order.line"]
1616
cls.blanket_order_wiz_obj = cls.env["sale.blanket.order.wizard"]
1717
cls.so_obj = cls.env["sale.order"]
18+
cls.product_pricelist_item_obj = cls.env["product.pricelist.item"]
19+
20+
settings = cls.env["res.config.settings"].with_user(cls.env.user).create({})
21+
settings.group_discount_per_so_line = True
22+
settings.set_values()
1823

1924
cls.payment_term = cls.env.ref("account.account_payment_term_immediate")
2025
cls.sale_pricelist = cls.env["product.pricelist"].create(
@@ -143,10 +148,22 @@ def test_01_create_blanket_order(self):
143148
}
144149
)
145150
blanket_order.sudo().onchange_partner_id()
146-
blanket_order.pricelist_id.discount_policy = "without_discount"
151+
152+
pricelist_item = self.product_pricelist_item_obj.search(
153+
[("pricelist_id", "=", blanket_order.pricelist_id.id)], limit=1
154+
)
155+
if not pricelist_item:
156+
pricelist_item = self.product_pricelist_item_obj.create(
157+
{
158+
"pricelist_id": blanket_order.pricelist_id.id,
159+
"fixed_price": 10.0,
160+
}
161+
)
162+
147163
blanket_order.line_ids[0].sudo().onchange_product()
148164
self.assertEqual(blanket_order.line_ids[0].taxes_id, self.tax1)
149-
blanket_order.pricelist_id.discount_policy = "with_discount"
165+
166+
pricelist_item.write({"compute_price": "percentage"})
150167
blanket_order.line_ids[0].sudo().onchange_product()
151168
blanket_order.line_ids[0].sudo()._get_display_price()
152169

sale_blanket_order/views/sale_blanket_order_line_views.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
<field name="arch" type="xml">
99
<list create="false">
1010
<field name="sequence" widget="handle" />
11-
<field name="name" invisible="1" />
1211
<field name="order_id" />
1312
<field
1413
name="product_id"
1514
context="{'partner_id':parent.partner_id, 'quantity':original_uom_qty, 'company_id': company_id}"
1615
/>
17-
<field name="product_uom" invisible="1" />
1816
<field name="price_unit" />
1917
<field name="date_schedule" />
2018
<field

sale_blanket_order/views/sale_order_views.xml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
<field name="currency_id" position="after">
99
<field name="blanket_order_id" invisible="1" />
1010
</field>
11-
<xpath
12-
expr="//field[@name='order_line']//list/field[@name='product_id']"
13-
position="after"
14-
>
15-
<field
16-
name="blanket_order_line"
17-
context="{'from_sale_order': True}"
18-
column_invisible="not parent.blanket_order_id"
19-
/>
20-
</xpath>
2111
<xpath expr="//field[@name='order_line']" position="attributes">
2212
<attribute name="context">{'from_sale_order': True}</attribute>
2313
</xpath>
@@ -28,9 +18,6 @@
2818
<field name="model">sale.order</field>
2919
<field name="inherit_id" ref="sale.view_order_form" />
3020
<field name="arch" type="xml">
31-
<xpath expr="//field[@name='order_line']" position="before">
32-
<field name="disable_adding_lines" invisible="1" />
33-
</xpath>
3421
<xpath expr="//field[@name='order_line']" position="attributes">
3522
<attribute
3623
name="options"

sale_blanket_order/wizard/create_sale_orders.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33
from collections import defaultdict
44

5-
from odoo import _, api, fields, models
5+
from odoo import api, fields, models
66
from odoo.exceptions import UserError
77
from odoo.tools import float_is_zero
88

@@ -22,7 +22,9 @@ def _default_order(self):
2222
)
2323
if blanket_order.state == "expired":
2424
raise UserError(
25-
_("You can't create a sale order from " "an expired blanket order!")
25+
self.env._(
26+
"You can't create a sale order from " "an expired blanket order!"
27+
)
2628
)
2729
return blanket_order
2830

@@ -37,16 +39,18 @@ def _check_valid_blanket_order_line(self, bo_lines):
3739
float_is_zero(line.remaining_uom_qty, precision_digits=precision)
3840
for line in bo_lines
3941
):
40-
raise UserError(_("The sale has already been completed."))
42+
raise UserError(self.env._("The sale has already been completed."))
4143

4244
for line in bo_lines:
4345
if line.order_id.state != "open":
4446
raise UserError(
45-
_("Sale Blanket Order %s is not open") % line.order_id.name
47+
self.env._("Sale Blanket Order %s is not open") % line.order_id.name
4648
)
4749
line_company_id = line.company_id and line.company_id.id or False
4850
if company_id is not False and line_company_id != company_id:
49-
raise UserError(_("You have to select lines " "from the same company."))
51+
raise UserError(
52+
self.env._("You have to select lines " "from the same company.")
53+
)
5054
else:
5155
company_id = line_company_id
5256

@@ -134,7 +138,9 @@ def create_sale_order(self):
134138
payment_term_id = 0
135139
for line in self.line_ids.filtered(lambda line: line.qty != 0.0):
136140
if line.qty > line.remaining_uom_qty:
137-
raise UserError(_("You can't order more than the remaining quantities"))
141+
raise UserError(
142+
self.env._("You can't order more than the remaining quantities")
143+
)
138144
vals = self._prepare_so_line_vals(line)
139145
order_lines_by_customer[line.partner_id.id].append((0, 0, vals))
140146

@@ -159,11 +165,11 @@ def create_sale_order(self):
159165
payment_term_id = False
160166

161167
if not order_lines_by_customer:
162-
raise UserError(_("An order can't be empty"))
168+
raise UserError(self.env._("An order can't be empty"))
163169

164170
if not currency_id:
165171
raise UserError(
166-
_(
172+
self.env._(
167173
"Can not create Sale Order from Blanket "
168174
"Order lines with different currencies"
169175
)
@@ -183,7 +189,7 @@ def create_sale_order(self):
183189
res.append(sale_order.id)
184190
return {
185191
"domain": [("id", "in", res)],
186-
"name": _("Sales Orders"),
192+
"name": self.env._("Sales Orders"),
187193
"view_type": "form",
188194
"view_mode": "list,form",
189195
"res_model": "sale.order",

0 commit comments

Comments
 (0)