Skip to content

Commit

Permalink
[IMP] purchase_cancel_reason: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
PrapassornS committed Mar 24, 2021
1 parent d64ea8d commit ac00d5c
Show file tree
Hide file tree
Showing 15 changed files with 118 additions and 92 deletions.
1 change: 0 additions & 1 deletion purchase_cancel_reason/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2013 Guewen Baconnier, Camptocamp SA
# Copyright 2017 Okia SPRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand Down
36 changes: 18 additions & 18 deletions purchase_cancel_reason/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# -*- coding: utf-8 -*-
# Copyright 2013 Guewen Baconnier, Camptocamp SA
# Copyright 2017 Okia SPRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{'name': 'Purchase Cancel Reason',
'version': '10.0.1.0.0',
'author': "Camptocamp,Odoo Community Association (OCA), Okia SPRL",
'category': 'Purchase',
'license': 'AGPL-3',
'complexity': 'normal',
'website': "https://github.com/OCA/purchase-workflow",
'depends': [
'purchase'],
'data': ['wizard/purchase_cancel_reason_view.xml',
'views/purchase_order.xml',
'security/ir.model.access.csv',
'data/purchase_order_cancel_reason.xml',
],
'auto_install': False,
'installable': True,
}
{
"name": "Purchase Cancel Reason",
"version": "10.0.1.0.0",
"author": "Camptocamp,Odoo Community Association (OCA), Okia SPRL",
"category": "Purchase",
"license": "AGPL-3",
"complexity": "normal",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase"],
"data": [
"wizard/purchase_cancel_reason_view.xml",
"views/purchase_order.xml",
"security/ir.model.access.csv",
"data/purchase_order_cancel_reason.xml",
],
"auto_install": False,
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="cancel_reason_only_quotation" model="purchase.order.cancel.reason">
<field name="name">Just for Quotation</field>
Expand Down
1 change: 0 additions & 1 deletion purchase_cancel_reason/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2013 Guewen Baconnier, Camptocamp SA
# Copyright 2017 Okia SPRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand Down
14 changes: 7 additions & 7 deletions purchase_cancel_reason/model/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2013 Guewen Baconnier, Camptocamp SA
# Copyright 2017 Okia SPRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models


class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
_inherit = "purchase.order"

cancel_reason_id = fields.Many2one(
'purchase.order.cancel.reason',
"purchase.order.cancel.reason",
string="Reason for cancellation",
readonly=True,
ondelete="restrict")
ondelete="restrict",
)


class PurchaseOrderCancelReason(models.Model):
_name = 'purchase.order.cancel.reason'
_description = 'Purchase Order Cancel Reason'
_name = "purchase.order.cancel.reason"
_description = "Purchase Order Cancel Reason"

name = fields.Char('Reason', required=True, translate=True)
name = fields.Char("Reason", required=True, translate=True)
1 change: 0 additions & 1 deletion purchase_cancel_reason/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2013 Guewen Baconnier, Camptocamp SA
# Copyright 2017 Okia SPRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand Down
74 changes: 41 additions & 33 deletions purchase_cancel_reason/tests/test_purchase_cancel_reason.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2013 Guewen Baconnier, Camptocamp SA
# Copyright 2017 Okia SPRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand All @@ -7,44 +6,53 @@


class TestPurchaseCancelReason(TransactionCase):

def setUp(self):
super(TestPurchaseCancelReason, self).setUp()
PurchaseOrder = self.env['purchase.order']
CancelReason = self.env['purchase.order.cancel.reason']
self.reason = CancelReason.create({'name': 'Canceled for tests'})
self.supplier = self.env['res.partner'].create({
'name': 'Supplier',
'supplier': True,
})
self.product = self.env['product.product'].create({
'name': 'Product'
})
uom = self.env.ref('product.product_uom_unit')
self.purchase_order = PurchaseOrder.create({
'partner_id': self.supplier.id,
'date_planned': fields.Datetime.now(),
'order_line': [(0, 0, {
'name': 'Line 1',
'product_id': self.product.id,
'product_qty': 8,
'product_uom': uom.id,
'price_unit': 100.00,
'date_planned': fields.Datetime.now(),
})],
})
PurchaseOrder = self.env["purchase.order"]
CancelReason = self.env["purchase.order.cancel.reason"]
self.reason = CancelReason.create({"name": "Canceled for tests"})
self.supplier = self.env["res.partner"].create(
{
"name": "Supplier",
"supplier": True,
}
)
self.product = self.env["product.product"].create({"name": "Product"})
uom = self.env.ref("product.product_uom_unit")
self.purchase_order = PurchaseOrder.create(
{
"partner_id": self.supplier.id,
"date_planned": fields.Datetime.now(),
"order_line": [
(
0,
0,
{
"name": "Line 1",
"product_id": self.product.id,
"product_qty": 8,
"product_uom": uom.id,
"price_unit": 100.00,
"date_planned": fields.Datetime.now(),
},
)
],
}
)

def test_purchase_order_cancel_reason(self):
"""
- Cancel a purchase order with the wizard asking for the reason
- Then the purchase order should be canceled and the reason stored
"""
PurchaseOrderCancel = self.env['purchase.order.cancel']
context = {'active_model': 'purchase.order',
'active_ids': [self.purchase_order.id], }
wizard = PurchaseOrderCancel.create({'reason_id': self.reason.id})
PurchaseOrderCancel = self.env["purchase.order.cancel"]
context = {
"active_model": "purchase.order",
"active_ids": [self.purchase_order.id],
}
wizard = PurchaseOrderCancel.create({"reason_id": self.reason.id})
wizard.with_context(context).confirm_cancel()
self.assertEqual(self.purchase_order.state, 'cancel',
'the purchase order should be canceled')
self.assertEqual(self.purchase_order.cancel_reason_id.id,
self.reason.id)
self.assertEqual(
self.purchase_order.state, "cancel", "the purchase order should be canceled"
)
self.assertEqual(self.purchase_order.cancel_reason_id.id, self.reason.id)
38 changes: 25 additions & 13 deletions purchase_cancel_reason/views/purchase_order.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="purchase_order_form" model="ir.ui.view">
<field name="name">purchase.order.form</field>
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form"/>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<xpath expr="//button[@name='button_cancel']" position="attributes">
<attribute name="invisible">True</attribute>
</xpath>
<xpath expr="//button[@name='button_cancel']" position="before">
<button name="%(action_purchase_order_cancel)d" states="draft,to approve,sent,purchase"
string="Cancel" type="action" groups="base.group_user"/>
<button
name="%(action_purchase_order_cancel)d"
states="draft,to approve,sent,purchase"
string="Cancel"
type="action"
groups="base.group_user"
/>
</xpath>
<xpath expr="/form/sheet/div/h1" position="after">
<h2 attrs="{'invisible': [('state', '!=', 'cancel')]}">
<label for="cancel_reason_id" string="Cancellation reason:"/>
<field name="cancel_reason_id" class="oe_inline" options='{"no_open": True}'/>
<label for="cancel_reason_id" string="Cancellation reason:" />
<field
name="cancel_reason_id"
class="oe_inline"
options='{"no_open": True}'
/>
</h2>
</xpath>
</field>
Expand All @@ -26,7 +35,7 @@
<field name="model">purchase.order.cancel.reason</field>
<field name="arch" type="xml">
<form string="Purchase Order Cancel Reasons">
<field name="name"/>
<field name="name" />
</form>
</field>
</record>
Expand All @@ -36,7 +45,7 @@
<field name="model">purchase.order.cancel.reason</field>
<field name="arch" type="xml">
<tree string="Purchase Order Cancel Reasons">
<field name="name"/>
<field name="name" />
</tree>
</field>
</record>
Expand All @@ -48,9 +57,12 @@
<field name="view_mode">tree,form</field>
</record>

<menuitem id="menu_purchase_order_cancel_reason"
parent="purchase.menu_purchase_config"
name="Purchase Order Cancel Reasons"
action="action_purchase_order_cancel_reason"
sequence="150" groups="purchase.group_purchase_manager"/>
<menuitem
id="menu_purchase_order_cancel_reason"
parent="purchase.menu_purchase_config"
name="Purchase Order Cancel Reasons"
action="action_purchase_order_cancel_reason"
sequence="150"
groups="purchase.group_purchase_manager"
/>
</odoo>
1 change: 0 additions & 1 deletion purchase_cancel_reason/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2013 Guewen Baconnier, Camptocamp SA
# Copyright 2017 Okia SPRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand Down
15 changes: 7 additions & 8 deletions purchase_cancel_reason/wizard/purchase_cancel_reason.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2013 Guewen Baconnier, Camptocamp SA
# Copyright 2017 Okia SPRL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand All @@ -8,23 +7,23 @@
class PurchaseOrderCancel(models.TransientModel):

""" Ask a reason for the purchase order cancellation."""
_name = 'purchase.order.cancel'

_name = "purchase.order.cancel"
_description = __doc__

reason_id = fields.Many2one(
'purchase.order.cancel.reason',
string='Reason',
required=True)
"purchase.order.cancel.reason", string="Reason", required=True
)

@api.multi
def confirm_cancel(self):
self.ensure_one()
act_close = {'type': 'ir.actions.act_window_close'}
purchase_ids = self._context.get('active_ids')
act_close = {"type": "ir.actions.act_window_close"}
purchase_ids = self._context.get("active_ids")
if purchase_ids is None:
return act_close
assert len(purchase_ids) == 1, "Only 1 purchase ID expected"
purchase = self.env['purchase.order'].browse(purchase_ids)
purchase = self.env["purchase.order"].browse(purchase_ids)
purchase.cancel_reason_id = self.reason_id.id
purchase.button_cancel()
return act_close
18 changes: 10 additions & 8 deletions purchase_cancel_reason/wizard/purchase_cancel_reason_view.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_purchase_order_cancel" model="ir.ui.view">
<field name="name">Reason for the cancellation</field>
Expand All @@ -10,15 +10,17 @@
purchase order.
</p>
<group>
<field name="reason_id" widget="selection"/>
<field name="reason_id" widget="selection" />
</group>
<footer>
<button name="confirm_cancel"
string="Confirm" type="object"
class="oe_highlight"/>
<button
name="confirm_cancel"
string="Confirm"
type="object"
class="oe_highlight"
/>
or
<button string="Cancel" class="oe_link"
special="cancel" />
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
Expand All @@ -30,7 +32,7 @@
<field name="res_model">purchase.order.cancel</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_purchase_order_cancel"/>
<field name="view_id" ref="view_purchase_order_cancel" />
<field name="target">new</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions setup/purchase_cancel_reason/odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
1 change: 1 addition & 0 deletions setup/purchase_cancel_reason/odoo/addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/purchase_cancel_reason/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit ac00d5c

Please sign in to comment.