Skip to content

Commit c0ee187

Browse files
author
phucph
committed
[MIG] purchase_package_qty: Migration to 18.0
1 parent d9cb43b commit c0ee187

20 files changed

+195
-416
lines changed

purchase_package_qty/__manifest__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,22 @@
2525

2626
{
2727
"name": "Purchase - Package Quantity",
28-
"version": "12.0.1.0.0",
28+
"version": "18.0.1.0.0",
2929
"category": "Purchase",
30-
"author": "GRAP, Druidoo",
30+
"author": "GRAP, Druidoo, Odoo Community Association (OCA)",
3131
"website": "https://github.com/OCA/purchase-workflow",
3232
"license": "AGPL-3",
3333
"depends": [
3434
"account",
3535
"product",
36-
"purchase_discount",
36+
"purchase_stock",
3737
],
3838
"data": [
3939
"views/product_supplierinfo_view.xml",
4040
"views/purchase_order_view.xml",
4141
"views/stock_picking_view.xml",
4242
"views/account_invoice_view.xml",
4343
"views/report_stockinventory.xml",
44-
"views/stock_inventory_view.xml",
4544
"views/report_invoice.xml",
4645
"data/function.xml",
4746
],

purchase_package_qty/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,4 @@
3131
from . import stock_move
3232
from . import account_invoice
3333
from . import account_invoice_line
34-
from . import stock_inventory
3534
from . import stock_move_line

purchase_package_qty/models/account_invoice.py

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727

2828

2929
class AccountInvoice(models.Model):
30-
_inherit = "account.invoice"
30+
_inherit = "account.move"
3131

32-
@api.onchange("purchase_id")
33-
def purchase_order_change(self):
34-
res = super().purchase_order_change()
32+
@api.onchange("purchase_vendor_bill_id", "purchase_id")
33+
def _onchange_purchase_auto_complete(self):
34+
res = super()._onchange_purchase_auto_complete()
3535
for line in self.invoice_line_ids:
3636
if line.quantity == 0:
3737
self.invoice_line_ids -= line
@@ -42,30 +42,3 @@ def purchase_order_change(self):
4242
line.package_qty and line.quantity / line.package_qty or 0
4343
)
4444
return res
45-
46-
@api.multi
47-
def get_taxes_values(self):
48-
tax_grouped = {}
49-
round_curr = self.currency_id.round
50-
for line in self.invoice_line_ids:
51-
if not line.account_id:
52-
continue
53-
price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
54-
if line.price_policy == "package":
55-
quantity = line.product_qty_package
56-
else:
57-
quantity = line.quantity
58-
taxes = line.invoice_line_tax_ids.compute_all(
59-
price_unit, self.currency_id, quantity, line.product_id, self.partner_id
60-
)["taxes"]
61-
for tax in taxes:
62-
val = self._prepare_tax_line_vals(line, tax)
63-
key = self.env["account.tax"].browse(tax["id"]).get_grouping_key(val)
64-
65-
if key not in tax_grouped:
66-
tax_grouped[key] = val
67-
tax_grouped[key]["base"] = round_curr(val["base"])
68-
else:
69-
tax_grouped[key]["amount"] += val["amount"]
70-
tax_grouped[key]["base"] += round_curr(val["base"])
71-
return tax_grouped

purchase_package_qty/models/account_invoice_line.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@
2727

2828

2929
class AccountInvoiceLine(models.Model):
30-
_inherit = "account.invoice.line"
30+
_inherit = "account.move.line"
3131

32-
package_qty = fields.Float(
33-
"Package Qty", help="""The quantity of products in the supplier package."""
34-
)
32+
package_qty = fields.Float(help="The quantity of products in the supplier package.")
3533
product_qty_package = fields.Float(
36-
"Number of packages", help="""The number of packages you'll buy."""
34+
"Number of packages", help="The number of packages you'll buy."
3735
)
3836
price_policy = fields.Selection(
3937
[("uom", "per UOM"), ("package", "per Package")],
40-
"Price Policy",
4138
default="uom",
4239
required=True,
4340
)
@@ -56,28 +53,10 @@ def onchange_product_qty_package(self):
5653
def onchange_package_qty(self):
5754
self.quantity = self.package_qty * self.product_qty_package
5855

59-
# pylint: disable=W8104
60-
@api.one
61-
@api.depends(
62-
"price_unit",
63-
"discount",
64-
"invoice_line_tax_ids",
65-
"quantity",
66-
"product_id",
67-
"invoice_id.partner_id",
68-
"invoice_id.currency_id",
69-
"invoice_id.company_id",
70-
"invoice_id.date_invoice",
71-
"invoice_id.date",
72-
"product_qty_package",
73-
"price_policy",
74-
)
75-
def _compute_price(self):
76-
if self.price_policy == "package":
77-
origin_quantiy = self.quantity
78-
self.quantity = self.product_qty_package
79-
res = super()._compute_price()
80-
self.quantity = origin_quantiy
81-
return res
82-
else:
83-
return super()._compute_price()
56+
@api.depends("display_type", "price_policy")
57+
def _compute_quantity(self):
58+
res = super()._compute_quantity()
59+
for line in self:
60+
if line.price_policy == "package":
61+
line.quantity = line.product_qty_package
62+
return res

purchase_package_qty/models/product_supplierinfo.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,39 +23,35 @@
2323
#
2424
##############################################################################
2525

26-
from odoo import _, api, fields, models
27-
28-
from odoo.addons import decimal_precision as dp
26+
from odoo import api, fields, models
27+
from odoo.exceptions import ValidationError
2928

3029

3130
class ProductSupplierinfo(models.Model):
3231
_inherit = "product.supplierinfo"
3332

3433
# Columns section
3534
package_qty = fields.Float(
36-
"Package Qty",
37-
digits=dp.get_precision("Product UoM"),
35+
digits="Product UoM",
3836
help="""The quantity of products in the supplier package."""
3937
""" You will always have to buy a multiple of this quantity.""",
4038
default=1,
4139
)
4240
indicative_package = fields.Boolean(
43-
"Indicative Package",
4441
help="""If checked, the system will not force you to purchase"""
4542
""" a strict multiple of package quantity""",
4643
default=False,
4744
)
4845
price_policy = fields.Selection(
4946
[("uom", "per UOM"), ("package", "per Package")],
50-
"Price Policy",
5147
default="uom",
5248
required=True,
5349
)
5450
base_price = fields.Float(
5551
"Price",
5652
required=False,
5753
default=0.00,
58-
digits=dp.get_precision("Product Price"),
54+
digits="Product Price",
5955
help="The price to purchase a product",
6056
)
6157
price = fields.Float(
@@ -67,7 +63,6 @@ class ProductSupplierinfo(models.Model):
6763
)
6864

6965
@api.depends("base_price", "price_policy", "package_qty")
70-
@api.multi
7166
def _compute_price(self):
7267
for psi in self:
7368
if psi.price_policy == "package":
@@ -77,32 +72,31 @@ def _compute_price(self):
7772
else:
7873
psi.price = psi.base_price
7974

80-
@api.model
81-
def create(self, vals):
82-
if not vals.get("base_price", False):
83-
if vals.get("price", False):
84-
vals["base_price"] = vals["price"]
85-
del vals["price"]
86-
else:
87-
vals["base_price"] = 0
88-
res = super().create(vals)
75+
@api.model_create_multi
76+
def create(self, vals_list):
77+
for vals in vals_list:
78+
if not vals.get("base_price"):
79+
if vals.get("price"):
80+
vals["base_price"] = vals["price"]
81+
del vals["price"]
82+
else:
83+
vals["base_price"] = 0
84+
res = super().create(vals_list)
8985
return res
9086

91-
@api.multi
9287
def write(self, vals):
93-
if not vals.get("base_price", False):
94-
if vals.get("price", False):
88+
if not vals.get("base_price"):
89+
if vals.get("price"):
9590
vals["base_price"] = vals["price"]
9691
del vals["price"]
9792
return super().write(vals)
9893

9994
# Constraints section
100-
@api.multi
10195
@api.constrains("package_qty")
10296
def _check_package_qty(self):
10397
for psi in self:
10498
if psi.package_qty == 0:
105-
raise ValueError(_("The package quantity cannot be 0."))
99+
raise ValidationError(self.env._("The package quantity cannot be 0."))
106100

107101
# Init section
108102
@api.model

purchase_package_qty/models/product_template.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929
class ProductTemplate(models.Model):
3030
_inherit = "product.template"
3131

32-
@api.depends(
33-
"seller_ids",
34-
)
35-
@api.multi
36-
def _compute_default_seller_id(self):
37-
for pt in self:
38-
pt.default_seller_id = pt.seller_ids and pt.seller_ids[0] or False
39-
4032
default_seller_id = fields.Many2one(
41-
string="Default Seller",
4233
comodel_name="product.supplierinfo",
4334
compute="_compute_default_seller_id",
4435
)
36+
37+
@api.depends("seller_ids")
38+
def _compute_default_seller_id(self):
39+
for pt in self:
40+
default_seller_id = False
41+
if pt.seller_ids:
42+
default_seller_id = pt.seller_ids[0]
43+
pt.default_seller_id = default_seller_id

purchase_package_qty/models/purchase_order.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
#
2424
##############################################################################
2525

26-
from odoo import api, models
26+
from odoo import models
2727

2828

2929
class PurchaseOrder(models.Model):
3030
_inherit = "purchase.order"
3131

32-
@api.multi
3332
def _add_supplier_to_product(self):
3433
# we have to override this method to modify the vals
3534
# Do not add a contact as a supplier
@@ -40,7 +39,7 @@ def _add_supplier_to_product(self):
4039
)
4140
for line in self.order_line:
4241
if (
43-
partner not in line.product_id.seller_ids.mapped("name")
42+
partner not in line.product_id.seller_ids.mapped("partner_id")
4443
and len(line.product_id.seller_ids) <= 10
4544
):
4645
supplierinfo = line._get_supplierinfovals(partner)
@@ -52,7 +51,6 @@ def _add_supplier_to_product(self):
5251
except Exception: # If no Write access rights -> just ignore
5352
break
5453

55-
@api.multi
5654
def action_view_picking(self):
5755
res = super().action_view_picking()
5856
res["context"].update({"readonly_by_pass": True})

0 commit comments

Comments
 (0)