Skip to content

Commit ddd5031

Browse files
teewuxkittiu
authored andcommitted
[IMP] purchase_exception: black, isort, prettier
1 parent d85c7c1 commit ddd5031

14 files changed

+179
-166
lines changed

purchase_exception/__manifest__.py

+12-15
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,18 @@
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
44

55
{
6-
'name': 'Purchase Exception',
7-
'summary': 'Custom exceptions on purchase order',
8-
'version': '12.0.1.1.0',
9-
'category': 'Generic Modules/Purchase',
10-
'author': "Akretion, Odoo Community Association (OCA)",
6+
"name": "Purchase Exception",
7+
"summary": "Custom exceptions on purchase order",
8+
"version": "12.0.1.1.0",
9+
"category": "Generic Modules/Purchase",
10+
"author": "Akretion, Odoo Community Association (OCA)",
1111
"website": "https://github.com/OCA/purchase-workflow",
12-
'depends': [
13-
'purchase',
14-
'base_exception',
12+
"depends": ["purchase", "base_exception",],
13+
"license": "AGPL-3",
14+
"data": [
15+
"data/purchase_exception_data.xml",
16+
"wizard/purchase_exception_confirm_view.xml",
17+
"views/purchase_view.xml",
1518
],
16-
'license': 'AGPL-3',
17-
'data': [
18-
'data/purchase_exception_data.xml',
19-
'wizard/purchase_exception_confirm_view.xml',
20-
'views/purchase_view.xml',
21-
],
22-
'installable': True,
19+
"installable": True,
2320
}
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo noupdate="1">
3-
43
<!-- Test Purchase Exceptions Scheduler-->
5-
<record model="ir.cron" forcecreate="True"
6-
id="ir_cron_test_po_order_except">
4+
<record model="ir.cron" forcecreate="True" id="ir_cron_test_po_order_except">
75
<field name="name">Purchase: Test Draft Orders Exception</field>
8-
<field name="model_id" ref="purchase.model_purchase_order"/>
6+
<field name="model_id" ref="purchase.model_purchase_order" />
97
<field name="state">code</field>
108
<field name="code">model.test_all_draft_orders()</field>
11-
<field name="user_id" ref="base.user_root"/>
9+
<field name="user_id" ref="base.user_root" />
1210
<field name="interval_number">20</field>
1311
<field name="interval_type">minutes</field>
1412
<field name="numbercall">-1</field>
1513
<field name="doall" eval="False" />
1614
<field name="active" eval="False" />
1715
</record>
18-
19-
<record id ="po_excep_no_email" model="exception.rule">
16+
<record id="po_excep_no_email" model="exception.rule">
2017
<field name="name">No email on vendor</field>
2118
<field name="description">No Email for Vendor</field>
2219
<field name="sequence">50</field>
2320
<field name="model">purchase.order</field>
2421
<field name="code">if not self.partner_id.email:
2522
failed=True</field>
26-
<field name="active" eval="False"/>
23+
<field name="active" eval="False" />
2724
</record>
28-
29-
<record id ="pol_excep_qty_check" model="exception.rule">
25+
<record id="pol_excep_qty_check" model="exception.rule">
3026
<field name="name">Quantity not negative</field>
3127
<field name="description">Purchase line quantity must be positive</field>
3228
<field name="sequence">50</field>
3329
<field name="model">purchase.order.line</field>
3430
<field name="code">if self.product_qty &lt; 0:
3531
failed=True</field>
36-
<field name="active" eval="False"/>
32+
<field name="active" eval="False" />
3733
</record>
38-
3934
</odoo>
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<?xml version='1.0' encoding='utf-8'?>
1+
<?xml version='1.0' encoding='utf-8' ?>
22
<odoo>
3-
<record id="ir_cron_test_po_order_except" model="ir.cron" forcecreate="True">
4-
<field name="code">model.test_all_draft_orders()</field>
5-
</record>
6-
<record id="po_excep_no_email" model="exception.rule">
7-
<!-- <field name="rule_group"/>-->
8-
<field name="code">if not self.partner_id.email:
3+
<record id="ir_cron_test_po_order_except" model="ir.cron" forcecreate="True">
4+
<field name="code">model.test_all_draft_orders()</field>
5+
</record>
6+
<record id="po_excep_no_email" model="exception.rule">
7+
<!-- <field name="rule_group"/>-->
8+
<field name="code">if not self.partner_id.email:
99
failed=True</field>
10-
</record>
11-
<record id="pol_excep_qty_check" model="exception.rule">
12-
<!-- <field name="rule_group"/>-->
13-
<field name="code">if self.product_qty &lt; 0:
10+
</record>
11+
<record id="pol_excep_qty_check" model="exception.rule">
12+
<!-- <field name="rule_group"/>-->
13+
<field name="code">if self.product_qty &lt; 0:
1414
failed=True</field>
15-
</record>
15+
</record>
1616
</odoo>

purchase_exception/migrations/12.0.1.0.1/post-migration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
@openupgrade.migrate()
77
def migrate(env, version):
88
openupgrade.load_data(
9-
env.cr, 'purchase_exception',
10-
'migrations/12.0.1.0.1/noupdate_changes.xml')
9+
env.cr, "purchase_exception", "migrations/12.0.1.0.1/noupdate_changes.xml"
10+
)

purchase_exception/models/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from . import exception_rule
32
from . import purchase
43
from . import purchase_line

purchase_exception/models/exception_rule.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
# Mourad EL HADJ MIMOUNE <[email protected]>
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
44

5-
from odoo import models, fields
5+
from odoo import fields, models
66

77

88
class ExceptionRule(models.Model):
9-
_inherit = 'exception.rule'
9+
_inherit = "exception.rule"
1010

11-
purchase_ids = fields.Many2many(
12-
comodel_name="purchase.order", string="Purchases")
11+
purchase_ids = fields.Many2many(comodel_name="purchase.order", string="Purchases")
1312
model = fields.Selection(
1413
selection_add=[
15-
('purchase.order', 'Purchase order'),
16-
('purchase.order.line', 'Purchase order line'),
17-
])
14+
("purchase.order", "Purchase order"),
15+
("purchase.order.line", "Purchase order line"),
16+
]
17+
)

purchase_exception/models/purchase.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111

1212
class PurchaseOrder(models.Model):
13-
_inherit = ['purchase.order', 'base.exception']
14-
_name = 'purchase.order'
15-
_order = 'main_exception_id asc, date_order desc, name desc'
13+
_inherit = ["purchase.order", "base.exception"]
14+
_name = "purchase.order"
15+
_order = "main_exception_id asc, date_order desc, name desc"
1616

1717
@api.model
1818
def test_all_draft_orders(self):
19-
order_set = self.search([('state', '=', 'draft')])
19+
order_set = self.search([("state", "=", "draft")])
2020
order_set.detect_exceptions()
2121
return True
2222

@@ -26,33 +26,35 @@ def _exception_rule_eval_context(self, rec):
2626
# We keep this only for backward compatibility
2727
res = super()._exception_rule_eval_context(rec)
2828
if res.get("purchase"):
29-
logger.warning("""
29+
logger.warning(
30+
"""
3031
For a full compatibility with future versions of this module,
3132
please use 'self' instead of 'purchase' in your
3233
custom exceptions rules.
33-
""")
34-
res['purchase'] = rec
34+
"""
35+
)
36+
res["purchase"] = rec
3537
return res
3638

3739
@api.model
3840
def _reverse_field(self):
39-
return 'purchase_ids'
41+
return "purchase_ids"
4042

4143
def detect_exceptions(self):
4244
all_exceptions = super().detect_exceptions()
43-
lines = self.mapped('order_line')
45+
lines = self.mapped("order_line")
4446
all_exceptions += lines.detect_exceptions()
4547
return all_exceptions
4648

47-
@api.constrains('ignore_exception', 'order_line', 'state')
49+
@api.constrains("ignore_exception", "order_line", "state")
4850
def purchase_check_exception(self):
49-
orders = self.filtered(lambda s: s.state == 'purchase')
51+
orders = self.filtered(lambda s: s.state == "purchase")
5052
if orders:
5153
orders._check_exception()
5254

53-
@api.onchange('order_line')
55+
@api.onchange("order_line")
5456
def onchange_ignore_exception(self):
55-
if self.state == 'purchase':
57+
if self.state == "purchase":
5658
self.ignore_exception = False
5759

5860
@api.multi
@@ -72,6 +74,5 @@ def button_draft(self):
7274

7375
@api.model
7476
def _get_popup_action(self):
75-
action = self.env.ref(
76-
'purchase_exception.action_purchase_exception_confirm')
77+
action = self.env.ref("purchase_exception.action_purchase_exception_confirm")
7778
return action

purchase_exception/models/purchase_line.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
44

55
import logging
6-
from odoo import api, models, fields
6+
7+
from odoo import api, fields, models
78

89
logger = logging.getLogger(__name__)
910

1011

1112
class PurchaseOrderLine(models.Model):
12-
_inherit = ['purchase.order.line', 'base.exception.method']
13-
_name = 'purchase.order.line'
13+
_inherit = ["purchase.order.line", "base.exception.method"]
14+
_name = "purchase.order.line"
1415

1516
ignore_exception = fields.Boolean(
16-
related='order_id.ignore_exception',
17-
store=True,
18-
string="Ignore Exceptions")
17+
related="order_id.ignore_exception", store=True, string="Ignore Exceptions"
18+
)
1919

2020
@api.multi
2121
def _get_main_records(self):
22-
return self.mapped('order_id')
22+
return self.mapped("order_id")
2323

2424
@api.model
2525
def _reverse_field(self):
26-
return 'purchase_ids'
26+
return "purchase_ids"
2727

2828
@api.multi
2929
def _detect_exceptions(self, rule):
3030
records = super()._detect_exceptions(rule)
31-
return records.mapped('order_id')
31+
return records.mapped("order_id")
3232

3333
@api.model
3434
def _exception_rule_eval_context(self, rec):
@@ -38,10 +38,12 @@ def _exception_rule_eval_context(self, rec):
3838
# code during v13 migration.
3939
res = super()._exception_rule_eval_context(rec)
4040
if res.get("purchase_line"):
41-
logger.warning("""
41+
logger.warning(
42+
"""
4243
For a full compatibility with future versions of this module,
4344
please use 'self' instead of 'purchase_line' in your
4445
custom exceptions rules.
45-
""")
46-
res['purchase_line'] = rec
46+
"""
47+
)
48+
res["purchase_line"] = rec
4749
return res

purchase_exception/readme/USAGE.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
22
:alt: Try me on Runbot
3-
:target: https://runbot.odoo-community.org/runbot/142/12.0
3+
:target: https://runbot.odoo-community.org/runbot/142/12.0

purchase_exception/tests/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
from . import test_purchase_exception

0 commit comments

Comments
 (0)