Skip to content

Commit a7c1512

Browse files
[18.0][MIG] sale_blanket_order: Migration to 18.0
25500
1 parent 5a8f2a4 commit a7c1512

File tree

14 files changed

+223
-207
lines changed

14 files changed

+223
-207
lines changed

sale_blanket_order/README.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Sale Blanket Orders
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
20-
:target: https://github.com/OCA/sale-workflow/tree/17.0/sale_blanket_order
20+
:target: https://github.com/OCA/sale-workflow/tree/18.0/sale_blanket_order
2121
:alt: OCA/sale-workflow
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-sale_blanket_order
23+
:target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_blanket_order
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -102,20 +102,20 @@ factors:
102102

103103
|image6|
104104

105-
.. |image1| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_blanket_order/static/description/BO_menu.png
106-
.. |image2| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_blanket_order/static/description/BO_form.png
107-
.. |image3| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_blanket_order/static/description/BO_actions.png
108-
.. |image4| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_blanket_order/static/description/PO_from_BO.png
109-
.. |image5| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_blanket_order/static/description/BO_lines.png
110-
.. |image6| image:: https://raw.githubusercontent.com/OCA/sale-workflow/17.0/sale_blanket_order/static/description/PO_BOLine.png
105+
.. |image1| image:: https://raw.githubusercontent.com/OCA/sale-workflow/18.0/sale_blanket_order/static/description/BO_menu.png
106+
.. |image2| image:: https://raw.githubusercontent.com/OCA/sale-workflow/18.0/sale_blanket_order/static/description/BO_form.png
107+
.. |image3| image:: https://raw.githubusercontent.com/OCA/sale-workflow/18.0/sale_blanket_order/static/description/BO_actions.png
108+
.. |image4| image:: https://raw.githubusercontent.com/OCA/sale-workflow/18.0/sale_blanket_order/static/description/PO_from_BO.png
109+
.. |image5| image:: https://raw.githubusercontent.com/OCA/sale-workflow/18.0/sale_blanket_order/static/description/BO_lines.png
110+
.. |image6| image:: https://raw.githubusercontent.com/OCA/sale-workflow/18.0/sale_blanket_order/static/description/PO_BOLine.png
111111

112112
Bug Tracker
113113
===========
114114

115115
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
116116
In case of trouble, please check there if your issue has already been reported.
117117
If you spotted it first, help us to smash it by providing a detailed and welcomed
118-
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_blanket_order%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
118+
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_blanket_order%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
119119

120120
Do not contact contributors directly about support or help with technical issues.
121121

@@ -166,6 +166,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
166166
mission is to support the collaborative development of Odoo features and
167167
promote its widespread use.
168168

169-
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/17.0/sale_blanket_order>`_ project on GitHub.
169+
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/18.0/sale_blanket_order>`_ project on GitHub.
170170

171171
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

sale_blanket_order/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"category": "Sale",
66
"license": "AGPL-3",
77
"author": "Acsone SA/NV, Odoo Community Association (OCA)",
8-
"version": "17.0.1.1.0",
8+
"version": "18.0.1.1.0",
99
"website": "https://github.com/OCA/sale-workflow",
1010
"summary": "Blanket Orders",
1111
"depends": ["uom", "sale_management"],

sale_blanket_order/data/ir_cron.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
name="nextcall"
1111
eval="(DateTime.now() + relativedelta(hour=00, minute=1, second=0)).strftime('%Y-%m-%d %H:%M:%S')"
1212
/>
13-
<field name="numbercall">-1</field>
14-
<field name="doall" eval="False" />
1513
<field name="model_id" ref="model_sale_blanket_order" />
1614
<field name="state">code</field>
1715
<field name="code">model.expire_orders()</field>

sale_blanket_order/models/blanket_orders.py

Lines changed: 28 additions & 42 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 SUPERUSER_ID, _, 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
@@ -62,13 +62,6 @@ def _compute_amount_all(self):
6262
required=True,
6363
)
6464
currency_id = fields.Many2one("res.currency", related="pricelist_id.currency_id")
65-
analytic_account_id = fields.Many2one(
66-
comodel_name="account.analytic.account",
67-
string="Analytic Account",
68-
copy=False,
69-
check_company=True,
70-
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
71-
)
7265
payment_term_id = fields.Many2one(
7366
"account.payment.term",
7467
string="Payment Terms",
@@ -110,7 +103,8 @@ def _compute_amount_all(self):
110103
sale_count = fields.Integer(compute="_compute_sale_count")
111104

112105
fiscal_position_id = fields.Many2one(
113-
"account.fiscal.position", string="Fiscal Position"
106+
"account.fiscal.position",
107+
check_company=True,
114108
)
115109

116110
amount_untaxed = fields.Monetary(
@@ -236,15 +230,15 @@ def onchange_partner_id(self):
236230

237231
if self.partner_id.user_id:
238232
values["user_id"] = self.partner_id.user_id.id
239-
if self.partner_id.team_id:
240-
values["team_id"] = self.partner_id.team_id.id
233+
if self.partner_id.user_id.sale_team_id:
234+
values["team_id"] = self.partner_id.user_id.sale_team_id.id
241235
self.update(values)
242236

243237
def unlink(self):
244238
for order in self:
245239
if order.state not in ("draft", "expired") or order._check_active_orders():
246240
raise UserError(
247-
_(
241+
self.env._(
248242
"You can not delete an open blanket or "
249243
"with active sale orders! "
250244
"Try to cancel it before."
@@ -256,12 +250,12 @@ def _validate(self):
256250
try:
257251
today = fields.Date.today()
258252
for order in self:
259-
assert order.validity_date, _("Validity date is mandatory")
260-
assert order.validity_date > today, _(
253+
assert order.validity_date, self.env._("Validity date is mandatory")
254+
assert order.validity_date > today, self.env._(
261255
"Validity date must be in the future"
262256
)
263-
assert order.partner_id, _("Partner is mandatory")
264-
assert len(order.line_ids) > 0, _("Must have some lines")
257+
assert order.partner_id, self.env._("Partner is mandatory")
258+
assert len(order.line_ids) > 0, self.env._("Must have some lines")
265259
order.line_ids._validate()
266260
except AssertionError as e:
267261
raise UserError(e) from e
@@ -292,7 +286,7 @@ def action_cancel(self):
292286
for order in self:
293287
if order._check_active_orders():
294288
raise UserError(
295-
_(
289+
self.env._(
296290
"You can not delete a blanket order with opened "
297291
"sale orders! "
298292
"Try to cancel them before."
@@ -419,9 +413,9 @@ def _compute_amount(self):
419413
product_uom = fields.Many2one("uom.uom", string="Unit of Measure")
420414
price_unit = fields.Float(string="Price", digits="Product Price")
421415
taxes_id = fields.Many2many(
422-
"account.tax",
423-
string="Taxes",
424-
domain=["|", ("active", "=", False), ("active", "=", True)],
416+
comodel_name="account.tax",
417+
context={"active_test": False},
418+
check_company=True,
425419
)
426420
date_schedule = fields.Date(string="Scheduled Date")
427421
original_uom_qty = fields.Float(
@@ -483,12 +477,14 @@ def _compute_amount(self):
483477
def _compute_display_name(self):
484478
if self.env.context.get("from_sale_order"):
485479
for record in self:
486-
name = "[%s]" % record.order_id.name
480+
name = f"[{record.order_id.name}]"
487481
if record.date_schedule:
488482
formatted_date = format_date(record.env, record.date_schedule)
489-
name += " - {}: {}".format(_("Date Scheduled"), formatted_date)
483+
name += " - {}: {}".format(
484+
self.env._("Date Scheduled"), formatted_date
485+
)
490486
name += " ({}: {} {})".format(
491-
_("remaining"),
487+
self.env._("remaining"),
492488
record.remaining_uom_qty,
493489
record.product_uom.name,
494490
)
@@ -511,12 +507,11 @@ def _get_real_price_currency(self, product, rule_id, qty, uom, pricelist_id):
511507
product_currency = None
512508
if rule_id:
513509
pricelist_item = PricelistItem.browse(rule_id)
514-
if pricelist_item.pricelist_id.discount_policy == "without_discount":
510+
if pricelist_item._show_discount():
515511
while (
516512
pricelist_item.base == "pricelist"
517513
and pricelist_item.base_pricelist_id
518-
and pricelist_item.base_pricelist_id.discount_policy
519-
== "without_discount"
514+
and pricelist_item._show_discount()
520515
):
521516
price, rule_id = pricelist_item.base_pricelist_id.with_context(
522517
uom=uom.id
@@ -571,9 +566,6 @@ def _get_display_price(self):
571566
currency=self.currency_id,
572567
)
573568

574-
if self.order_id.pricelist_id.discount_policy == "with_discount":
575-
return pricelist_price
576-
577569
if not self.pricelist_item_id:
578570
# No pricelist rule found => no discount from pricelist
579571
return pricelist_price
@@ -590,7 +582,7 @@ def _get_pricelist_price_before_discount(self):
590582

591583
return self.pricelist_item_id._compute_price_before_discount(
592584
product=self.product_id,
593-
quantity=self.product_uom_qty or 1.0,
585+
quantity=self.original_uom_qty or 1.0,
594586
uom=self.product_uom,
595587
date=fields.Date.today(),
596588
currency=self.currency_id,
@@ -616,15 +608,9 @@ def onchange_product(self):
616608
self.name = name
617609

618610
fpos = self.order_id.fiscal_position_id
619-
if self.env.uid == SUPERUSER_ID:
620-
company_id = self.env.company.id
621-
self.taxes_id = fpos.map_tax(
622-
self.product_id.taxes_id.filtered(
623-
lambda r: r.company_id.id == company_id
624-
)
625-
)
626-
else:
627-
self.taxes_id = fpos.map_tax(self.product_id.taxes_id)
611+
self.taxes_id = fpos.map_tax(
612+
self.product_id.taxes_id._filter_taxes_by_company(self.company_id)
613+
)
628614

629615
@api.depends(
630616
"sale_lines.order_id.state",
@@ -682,10 +668,10 @@ def _validate(self):
682668
for line in self:
683669
assert (
684670
not line.display_type and line.price_unit > 0.0
685-
) or line.display_type, _("Price must be greater than zero")
671+
) or line.display_type, self.env._("Price must be greater than zero")
686672
assert (
687673
not line.display_type and line.original_uom_qty > 0.0
688-
) or line.display_type, _("Quantity must be greater than zero")
674+
) or line.display_type, self.env._("Quantity must be greater than zero")
689675
except AssertionError as e:
690676
raise UserError(e) from e
691677

@@ -729,7 +715,7 @@ def write(self, values):
729715
lambda line: line.display_type != values.get("display_type")
730716
):
731717
raise UserError(
732-
_(
718+
self.env._(
733719
"""
734720
You cannot change the type of a sale order line.
735721
Instead you should delete the current line and create a new line

sale_blanket_order/models/sale_orders.py

Lines changed: 18 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

@@ -15,6 +15,9 @@ class SaleOrder(models.Model):
1515
string="Origin blanket order",
1616
related="order_line.blanket_order_line.order_id",
1717
)
18+
disable_adding_lines = fields.Boolean(
19+
compute="_compute_disable_adding_lines",
20+
)
1821

1922
@api.model
2023
def _check_exchausted_blanket_order_line(self):
@@ -27,7 +30,7 @@ def action_confirm(self):
2730
for order in self:
2831
if order._check_exchausted_blanket_order_line():
2932
raise ValidationError(
30-
_(
33+
self.env._(
3134
"Cannot confirm order %s as one of the lines refers "
3235
"to a blanket order that has no remaining quantity."
3336
)
@@ -41,12 +44,22 @@ def check_partner_id(self):
4144
if line.blanket_order_line:
4245
if line.blanket_order_line.partner_id != self.partner_id:
4346
raise ValidationError(
44-
_(
47+
self.env._(
4548
"The customer must be equal to the "
4649
"blanket order lines customer"
4750
)
4851
)
4952

53+
@api.depends("blanket_order_id")
54+
@api.depends_context("uid")
55+
def _compute_disable_adding_lines(self):
56+
self.disable_adding_lines = False
57+
if self.env.user.has_group(
58+
"sale_blanket_order.blanket_orders_disable_adding_lines"
59+
):
60+
for order in self:
61+
order.disable_adding_lines = order.blanket_order_id
62+
5063

5164
class SaleOrderLine(models.Model):
5265
_inherit = "sale.order.line"
@@ -166,7 +179,7 @@ def check_product_id(self):
166179
and line.product_id != line.blanket_order_line.product_id
167180
):
168181
raise ValidationError(
169-
_(
182+
self.env._(
170183
"The product in the blanket order and in the "
171184
"sales order must match"
172185
)
@@ -178,7 +191,7 @@ def check_currency(self):
178191
if line.blanket_order_line:
179192
if line.currency_id != line.blanket_order_line.order_id.currency_id:
180193
raise ValidationError(
181-
_(
194+
self.env._(
182195
"The currency of the blanket order must match with "
183196
"that of the sale order."
184197
)

sale_blanket_order/report/templates.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<t t-call="web.external_layout">
55
<t t-set="doc" t-value="doc.with_context({'lang':doc.partner_id.lang})" />
66
<div class="page">
7-
<div class="oe_structure" />
7+
<div id="oe_structure_div_01" class="oe_structure" />
88
<div class="row">
99
<div class="col-xs-6">
1010
<div
@@ -160,7 +160,7 @@
160160
</div>
161161

162162
<p t-field="doc.note" />
163-
<div class="oe_structure" />
163+
<div id="oe_structure_div_02" class="oe_structure" />
164164
</div>
165165
</t>
166166
</template>

0 commit comments

Comments
 (0)