Skip to content

Commit d9cb43b

Browse files
author
phucph
committed
[IMP] purchase_package_qty: pre-commit auto fixes
1 parent 8d3624a commit d9cb43b

20 files changed

+490
-374
lines changed

purchase_package_qty/__manifest__.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@
2424
##############################################################################
2525

2626
{
27-
'name': 'Purchase - Package Quantity',
28-
'version': '12.0.1.0.0',
29-
'category': 'Purchase',
30-
'author': 'GRAP, Druidoo',
31-
'website': 'https://cooplalouve.fr',
32-
'license': 'AGPL-3',
33-
'depends': [
34-
'account',
35-
'product',
36-
'purchase_discount',
27+
"name": "Purchase - Package Quantity",
28+
"version": "12.0.1.0.0",
29+
"category": "Purchase",
30+
"author": "GRAP, Druidoo",
31+
"website": "https://github.com/OCA/purchase-workflow",
32+
"license": "AGPL-3",
33+
"depends": [
34+
"account",
35+
"product",
36+
"purchase_discount",
3737
],
38-
'data': [
39-
'views/product_supplierinfo_view.xml',
40-
'views/purchase_order_view.xml',
41-
'views/stock_picking_view.xml',
42-
'views/account_invoice_view.xml',
43-
'views/report_stockinventory.xml',
44-
'views/stock_inventory_view.xml',
45-
'views/report_invoice.xml',
46-
'data/function.xml',
38+
"data": [
39+
"views/product_supplierinfo_view.xml",
40+
"views/purchase_order_view.xml",
41+
"views/stock_picking_view.xml",
42+
"views/account_invoice_view.xml",
43+
"views/report_stockinventory.xml",
44+
"views/stock_inventory_view.xml",
45+
"views/report_invoice.xml",
46+
"data/function.xml",
4747
],
4848
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="UTF-8" ?>
22
<!-- ********************************************************************** -->
33
<!--Purchase - Package Quantity Module for Odoo -->
44
<!--Copyright (C) 2019-Today: La Louve (<https://cooplalouve.fr>) -->
@@ -7,20 +7,17 @@
77
<!--License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
88
<!--@author Julien Weste -->
99
<!--@author Sylvain LE GAL (https://twitter.com/legalsylvain) -->
10-
1110
<!--This program is free software: you can redistribute it and/or modify -->
1211
<!--it under the terms of the GNU Affero General Public License as -->
1312
<!--published by the Free Software Foundation, either version 3 of the -->
1413
<!--License, or (at your option) any later version. -->
15-
1614
<!--This program is distributed in the hope that it will be useful, -->
1715
<!--but WITHOUT ANY WARRANTY; without even the implied warranty of -->
1816
<!--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
1917
<!--GNU Affero General Public License for more details. -->
20-
2118
<!--You should have received a copy of the GNU Affero General Public License-->
2219
<!--along with this program. If not, see <http://www.gnu.org/licenses/>. -->
2320
<!-- ********************************************************************** -->
2421
<odoo>
25-
<function model="product.supplierinfo" name="_init_package_qty"/>
22+
<function model="product.supplierinfo" name="_init_package_qty" />
2623
</odoo>

purchase_package_qty/models/account_invoice.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,20 @@
2727

2828

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

32-
@api.onchange('purchase_id')
32+
@api.onchange("purchase_id")
3333
def purchase_order_change(self):
34-
res = super(AccountInvoice, self).purchase_order_change()
34+
res = super().purchase_order_change()
3535
for line in self.invoice_line_ids:
3636
if line.quantity == 0:
3737
self.invoice_line_ids -= line
3838
else:
3939
line.price_policy = line.purchase_line_id.price_policy
4040
line.package_qty = line.purchase_line_id.package_qty
41-
line.product_qty_package = line.package_qty and\
42-
line.quantity / line.package_qty or 0
41+
line.product_qty_package = (
42+
line.package_qty and line.quantity / line.package_qty or 0
43+
)
4344
return res
4445

4546
@api.multi
@@ -50,22 +51,21 @@ def get_taxes_values(self):
5051
if not line.account_id:
5152
continue
5253
price_unit = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
53-
if line.price_policy == 'package':
54+
if line.price_policy == "package":
5455
quantity = line.product_qty_package
5556
else:
5657
quantity = line.quantity
5758
taxes = line.invoice_line_tax_ids.compute_all(
58-
price_unit, self.currency_id, quantity, line.product_id,
59-
self.partner_id)['taxes']
59+
price_unit, self.currency_id, quantity, line.product_id, self.partner_id
60+
)["taxes"]
6061
for tax in taxes:
6162
val = self._prepare_tax_line_vals(line, tax)
62-
key = self.env['account.tax'].browse(
63-
tax['id']).get_grouping_key(val)
63+
key = self.env["account.tax"].browse(tax["id"]).get_grouping_key(val)
6464

6565
if key not in tax_grouped:
6666
tax_grouped[key] = val
67-
tax_grouped[key]['base'] = round_curr(val['base'])
67+
tax_grouped[key]["base"] = round_curr(val["base"])
6868
else:
69-
tax_grouped[key]['amount'] += val['amount']
70-
tax_grouped[key]['base'] += round_curr(val['base'])
69+
tax_grouped[key]["amount"] += val["amount"]
70+
tax_grouped[key]["base"] += round_curr(val["base"])
7171
return tax_grouped

purchase_package_qty/models/account_invoice_line.py

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,44 +27,57 @@
2727

2828

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

3232
package_qty = fields.Float(
33-
'Package Qty',
34-
help="""The quantity of products in the supplier package.""")
33+
"Package Qty", help="""The quantity of products in the supplier package."""
34+
)
3535
product_qty_package = fields.Float(
36-
'Number of packages', help="""The number of packages you'll buy.""")
36+
"Number of packages", help="""The number of packages you'll buy."""
37+
)
3738
price_policy = fields.Selection(
38-
[('uom', 'per UOM'), ('package', 'per Package')], "Price Policy",
39-
default='uom', required=True)
39+
[("uom", "per UOM"), ("package", "per Package")],
40+
"Price Policy",
41+
default="uom",
42+
required=True,
43+
)
4044

41-
@api.onchange('quantity')
45+
@api.onchange("quantity")
4246
def onchange_product_qty(self):
4347
if self.package_qty:
4448
self.product_qty_package = self.quantity / self.package_qty
4549

46-
@api.onchange('product_qty_package')
50+
@api.onchange("product_qty_package")
4751
def onchange_product_qty_package(self):
4852
if self.product_qty_package == int(self.product_qty_package):
4953
self.quantity = self.package_qty * self.product_qty_package
5054

51-
@api.onchange('package_qty')
55+
@api.onchange("package_qty")
5256
def onchange_package_qty(self):
5357
self.quantity = self.package_qty * self.product_qty_package
5458

5559
# pylint: disable=W8104
5660
@api.one
5761
@api.depends(
58-
'price_unit', 'discount', 'invoice_line_tax_ids', 'quantity',
59-
'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id',
60-
'invoice_id.company_id', 'invoice_id.date_invoice', 'invoice_id.date',
61-
'product_qty_package', 'price_policy')
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+
)
6275
def _compute_price(self):
63-
if self.price_policy == 'package':
76+
if self.price_policy == "package":
6477
origin_quantiy = self.quantity
6578
self.quantity = self.product_qty_package
66-
res = super(AccountInvoiceLine, self)._compute_price()
79+
res = super()._compute_price()
6780
self.quantity = origin_quantiy
6881
return res
6982
else:
70-
return super(AccountInvoiceLine, self)._compute_price()
83+
return super()._compute_price()

purchase_package_qty/models/product_supplierinfo.py

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,54 @@
2323
#
2424
##############################################################################
2525

26-
from odoo import models, fields, api, _
26+
from odoo import _, api, fields, models
27+
2728
from odoo.addons import decimal_precision as dp
2829

2930

3031
class ProductSupplierinfo(models.Model):
31-
_inherit = 'product.supplierinfo'
32+
_inherit = "product.supplierinfo"
3233

3334
# Columns section
3435
package_qty = fields.Float(
35-
'Package Qty', digits=dp.get_precision('Product UoM'),
36+
"Package Qty",
37+
digits=dp.get_precision("Product UoM"),
3638
help="""The quantity of products in the supplier package."""
3739
""" You will always have to buy a multiple of this quantity.""",
38-
default=1)
40+
default=1,
41+
)
3942
indicative_package = fields.Boolean(
40-
'Indicative Package',
43+
"Indicative Package",
4144
help="""If checked, the system will not force you to purchase"""
4245
""" a strict multiple of package quantity""",
43-
default=False)
46+
default=False,
47+
)
4448
price_policy = fields.Selection(
45-
[('uom', 'per UOM'), ('package', 'per Package')], "Price Policy",
46-
default='uom', required=True)
49+
[("uom", "per UOM"), ("package", "per Package")],
50+
"Price Policy",
51+
default="uom",
52+
required=True,
53+
)
4754
base_price = fields.Float(
48-
'Price', required=False, default=0.00,
49-
digits=dp.get_precision('Product Price'),
50-
help="The price to purchase a product")
55+
"Price",
56+
required=False,
57+
default=0.00,
58+
digits=dp.get_precision("Product Price"),
59+
help="The price to purchase a product",
60+
)
5161
price = fields.Float(
52-
"Price per Unit", compute='_compute_price',
53-
required=False, store=True, readonly=True)
62+
"Price per Unit",
63+
compute="_compute_price",
64+
required=False,
65+
store=True,
66+
readonly=True,
67+
)
5468

55-
@api.depends('base_price', 'price_policy', 'package_qty')
69+
@api.depends("base_price", "price_policy", "package_qty")
5670
@api.multi
5771
def _compute_price(self):
5872
for psi in self:
59-
if psi.price_policy == 'package':
73+
if psi.price_policy == "package":
6074
if psi.package_qty == 0:
6175
psi.package_qty = 1
6276
psi.price = psi.base_price / psi.package_qty
@@ -65,30 +79,30 @@ def _compute_price(self):
6579

6680
@api.model
6781
def create(self, vals):
68-
if not vals.get('base_price', False):
69-
if vals.get('price', False):
70-
vals['base_price'] = vals['price']
71-
del vals['price']
82+
if not vals.get("base_price", False):
83+
if vals.get("price", False):
84+
vals["base_price"] = vals["price"]
85+
del vals["price"]
7286
else:
73-
vals['base_price'] = 0
74-
res = super(ProductSupplierinfo, self).create(vals)
87+
vals["base_price"] = 0
88+
res = super().create(vals)
7589
return res
7690

7791
@api.multi
7892
def write(self, vals):
79-
if not vals.get('base_price', False):
80-
if vals.get('price', False):
81-
vals['base_price'] = vals['price']
82-
del vals['price']
83-
return super(ProductSupplierinfo, self).write(vals)
93+
if not vals.get("base_price", False):
94+
if vals.get("price", False):
95+
vals["base_price"] = vals["price"]
96+
del vals["price"]
97+
return super().write(vals)
8498

8599
# Constraints section
86100
@api.multi
87-
@api.constrains('package_qty')
101+
@api.constrains("package_qty")
88102
def _check_package_qty(self):
89103
for psi in self:
90104
if psi.package_qty == 0:
91-
raise ValueError(_('The package quantity cannot be 0.'))
105+
raise ValueError(_("The package quantity cannot be 0."))
92106

93107
# Init section
94108
@api.model
@@ -97,9 +111,9 @@ def _init_package_qty(self):
97111
for psi in psi_ids:
98112
vals = {}
99113
if not psi.package_qty:
100-
vals['package_qty'] = max(psi.min_qty, 1)
114+
vals["package_qty"] = max(psi.min_qty, 1)
101115
if not psi.base_price:
102-
vals['base_price'] = psi.price
116+
vals["base_price"] = psi.price
103117
if vals:
104118
psi.write(vals)
105119
return psi_ids.ids

purchase_package_qty/models/product_template.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@
2727

2828

2929
class ProductTemplate(models.Model):
30-
_inherit = 'product.template'
30+
_inherit = "product.template"
3131

32-
@api.depends('seller_ids',)
32+
@api.depends(
33+
"seller_ids",
34+
)
3335
@api.multi
3436
def _compute_default_seller_id(self):
3537
for pt in self:
3638
pt.default_seller_id = pt.seller_ids and pt.seller_ids[0] or False
3739

3840
default_seller_id = fields.Many2one(
39-
string='Default Seller',
40-
comodel_name='product.supplierinfo',
41-
compute='_compute_default_seller_id',)
41+
string="Default Seller",
42+
comodel_name="product.supplierinfo",
43+
compute="_compute_default_seller_id",
44+
)

purchase_package_qty/models/purchase_order.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,25 @@
2727

2828

2929
class PurchaseOrder(models.Model):
30-
_inherit = 'purchase.order'
30+
_inherit = "purchase.order"
3131

3232
@api.multi
3333
def _add_supplier_to_product(self):
3434
# we have to override this method to modify the vals
3535
# Do not add a contact as a supplier
36-
partner = self.partner_id if not self.partner_id.parent_id\
36+
partner = (
37+
self.partner_id
38+
if not self.partner_id.parent_id
3739
else self.partner_id.parent_id
40+
)
3841
for line in self.order_line:
39-
if partner not in line.product_id.seller_ids.mapped('name') and\
40-
len(line.product_id.seller_ids) <= 10:
42+
if (
43+
partner not in line.product_id.seller_ids.mapped("name")
44+
and len(line.product_id.seller_ids) <= 10
45+
):
4146
supplierinfo = line._get_supplierinfovals(partner)
4247
vals = {
43-
'seller_ids': [(0, 0, supplierinfo)],
48+
"seller_ids": [(0, 0, supplierinfo)],
4449
}
4550
try:
4651
line.product_id.write(vals)
@@ -49,8 +54,6 @@ def _add_supplier_to_product(self):
4954

5055
@api.multi
5156
def action_view_picking(self):
52-
res = super(PurchaseOrder, self).action_view_picking()
53-
res['context'].update({
54-
'readonly_by_pass': True
55-
})
57+
res = super().action_view_picking()
58+
res["context"].update({"readonly_by_pass": True})
5659
return res

0 commit comments

Comments
 (0)