Skip to content

Commit ff4cbc3

Browse files
benwilligdsolanki-initos
authored andcommitted
[MIG] purchase_fop_shipping migration to v13
1 parent 552b8b7 commit ff4cbc3

12 files changed

+154
-127
lines changed

purchase_fop_shipping/__init__.py

100755100644
-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
# -*- coding: utf-8 -*-
2-
31
from . import models

purchase_fop_shipping/__manifest__.py

100755100644
+10-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
# -*- coding: utf-8 -*-
21
# © 2017 Akretion (http://www.akretion.com)
32
# @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
43
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
54

65
{
76
"name": "Purchase Free-Of-Paiment shipping",
8-
'version': '10.0.1.0.0',
7+
'version': '13.0.1.0.0',
98
'author': "Akretion,Odoo Community Association (OCA)",
9+
'website': "https://github.com/OCA/purchase-workflow",
1010
'maintainer': 'Akretion',
1111
'license': 'AGPL-3',
1212
'category': 'Purchase',
13-
'depends': ['purchase'],
13+
'depends': [
14+
'purchase',
15+
],
1416
'website': 'http://www.akretion.com/',
15-
'data': ['views/purchase_view.xml',
16-
'views/partner_view.xml',
17-
],
17+
'data': [
18+
'security/res_groups.xml',
19+
'views/purchase_order.xml',
20+
'views/res_partner.xml',
21+
],
1822
'installable': True,
1923
}

purchase_fop_shipping/models/__init__.py

100755100644
-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32
from . import partner
43
from . import purchase

purchase_fop_shipping/models/partner.py

100755100644
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# -*- coding: utf-8 -*-
21
# © 2014-2016 Akretion (http://www.akretion.com)
32
# @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
43
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
54

6-
from odoo import models, fields
5+
from odoo import fields, models
76

87

98
class ResPartner(models.Model):
10-
_inherit = 'res.partner'
9+
_inherit = "res.partner"
1110

1211
fop_shipping = fields.Float(
13-
'FOP shipping', help='Min purchase order amount for FOP shipping',)
12+
string="FOP shipping", help="Min purchase order amount for FOP shipping",
13+
)

purchase_fop_shipping/models/purchase.py

100755100644
+24-16
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
1-
# -*- coding: utf-8 -*-
21
# © 2017 Akretion (http://www.akretion.com)
32
# @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
43
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
54

6-
from odoo.exceptions import Warning as UserError
5+
from odoo.exceptions import UserError
76
from odoo import models, fields, api, _
87

98

109
class PurchaseOrder(models.Model):
1110

1211
_inherit = "purchase.order"
12+
1313
fop_reached = fields.Boolean(
1414
string='FOP reached',
1515
help='Free-Of-Payment shipping reached',
16-
compute='_fop_shipping_reached')
16+
compute='_compute_fop_reached',
17+
)
1718
force_order_under_fop = fields.Boolean(
1819
string='Confirm under FOP',
19-
help='Force confirm purchase order under Free-Of-Payment shipping',)
20+
help='Force confirm purchase order under Free-Of-Payment shipping',
21+
)
2022
fop_shipping = fields.Float(
21-
'FOP shipping',
23+
string='FOP shipping',
2224
related='partner_id.fop_shipping',
2325
readonly=True,
24-
help='Min purchase order amount for Free-Of-Payment shipping',)
26+
help='Min purchase order amount for Free-Of-Payment shipping',
27+
)
2528

26-
@api.multi
27-
@api.depends('amount_total', 'partner_id.fop_shipping')
28-
def _fop_shipping_reached(self):
29+
@api.depends(
30+
'amount_total',
31+
'partner_id.fop_shipping'
32+
)
33+
def _compute_fop_reached(self):
2934
for record in self:
3035
record.fop_reached = record.amount_total >\
3136
record.partner_id.fop_shipping
3237

33-
@api.multi
3438
def button_approve(self, force=False):
35-
for po in self:
36-
if not po.force_order_under_fop and not po.fop_reached:
37-
raise UserError(
38-
_('You cannot confirm a purchase order with amount under '
39-
'FOP shipping. To force confirm you must belongs to "FOP'
40-
' shipping Manager".'))
39+
self._check_fop_shipping()
4140
result = super(PurchaseOrder, self).button_approve(force=force)
4241
return result
42+
43+
def _check_fop_shipping(self):
44+
for po in self:
45+
if not po.force_order_under_fop and not po.fop_reached:
46+
raise UserError(_(
47+
'You cannot confirm a purchase order with amount under '
48+
'FOP shipping. To force confirm you must belongs to "FOP'
49+
' shipping Manager".'
50+
))
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<odoo>
3-
<data noupdate="0">
43

54
<record id="group_fop_shipping_purchase_manager" model="res.groups">
65
<field name="name">FOP shipping Manager</field>
@@ -9,5 +8,4 @@
98
<field name="users" eval="[(4, ref('base.user_root'))]"/>
109
</record>
1110

12-
</data>
13-
</odoo>
11+
</odoo>
-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
# -*- coding: utf-8 -*-
21
from . import test_fop_shipping
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,71 @@
1-
# -*- coding: utf-8 -*-
21
# © 2017 Akretion (http://www.akretion.com)
32
# @author Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
43
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
54

6-
import openerp.tests.common as common
7-
from openerp.exceptions import Warning as UserError
8-
from openerp import fields
9-
10-
11-
class TestPurchaseOrder(common.TransactionCase):
12-
13-
def setUp(self):
14-
super(TestPurchaseOrder, self).setUp()
15-
self.product_1 = self.env.ref('product.product_product_4')
16-
self.product_2 = self.env.ref('product.product_product_5b')
17-
self.partner_3 = self.env.ref('base.res_partner_3')
18-
self.partner_3.fop_shipping = 250
19-
po_model = self.env['purchase.order.line']
20-
self.purchase_order1 = self.env['purchase.order'].create(
21-
{'partner_id': self.partner_3.id})
22-
self.po_line_1 = po_model.create(
23-
{'order_id': self.purchase_order1.id,
24-
'product_id': self.product_1.id,
25-
'date_planned': fields.Datetime.now(),
26-
'name': 'Test',
27-
'product_qty': 1.0,
28-
'product_uom': self.product_1.uom_id.id,
29-
'price_unit': 100.0})
30-
self.purchase_order2 = self.env['purchase.order'].create(
31-
{'partner_id': self.partner_3.id})
32-
self.po_line_2 = po_model.create(
33-
{'order_id': self.purchase_order2.id,
34-
'product_id': self.product_2.id,
35-
'date_planned': fields.Datetime.now(),
36-
'name': 'Test',
37-
'product_qty': 10.0,
38-
'product_uom': self.product_2.uom_id.id,
39-
'price_unit': 45.0})
40-
41-
def test_purchase_order_vals(self):
42-
with self.assertRaises(UserError):
43-
self.purchase_order1.button_approve()
44-
self.purchase_order2.button_approve()
45-
self.assertEqual(self.purchase_order1.state, 'draft')
46-
self.assertEqual(self.purchase_order2.state, 'purchase')
47-
self.purchase_order1.force_order_under_fop = True
48-
self.purchase_order1.button_approve()
49-
self.assertEqual(self.purchase_order1.state, 'purchase')
5+
from odoo import fields
6+
from odoo.exceptions import UserError
7+
from odoo.tests.common import SavepointCase
8+
9+
10+
class TestPurchaseOrder(SavepointCase):
11+
12+
@classmethod
13+
def setUpClass(cls):
14+
super(TestPurchaseOrder, cls).setUpClass()
15+
cls.Product = cls.env['product.product']
16+
cls.Purchase = cls.env['purchase.order']
17+
cls.PurchaseLine = cls.env['purchase.order.line']
18+
19+
cls.product_1 = cls.Product.create({
20+
'name': 'Product',
21+
'type': 'consu',
22+
})
23+
24+
cls.partner_3 = cls.env.ref('base.res_partner_3')
25+
cls.partner_3.fop_shipping = 250
26+
27+
def test_fop_shipping_reached1(self):
28+
po = self.Purchase.create({
29+
'partner_id': self.partner_3.id,
30+
})
31+
self.PurchaseLine.create({
32+
'order_id': po.id,
33+
'product_id': self.product_1.id,
34+
'date_planned': fields.Datetime.now(),
35+
'name': 'Test',
36+
'product_qty': 1.0,
37+
'product_uom': self.product_1.uom_id.id,
38+
'price_unit': 100.0,
39+
})
40+
41+
self.assertFalse(po.fop_reached)
42+
43+
with self.assertRaises(UserError) as e, self.env.cr.savepoint():
44+
po.button_approve()
45+
self.assertTrue(
46+
"You cannot confirm a purchase order with amount under "
47+
"FOP shipping"
48+
in e.exception.name
49+
)
50+
51+
po.force_order_under_fop = True
52+
po.button_approve()
53+
self.assertEqual(po.state, 'purchase')
54+
55+
def test_fop_shipping_reached2(self):
56+
po = self.Purchase.create({
57+
'partner_id': self.partner_3.id,
58+
})
59+
self.PurchaseLine.create({
60+
'order_id': po.id,
61+
'product_id': self.product_1.id,
62+
'date_planned': fields.Datetime.now(),
63+
'name': 'Test',
64+
'product_qty': 10,
65+
'product_uom': self.product_1.uom_id.id,
66+
'price_unit': 45,
67+
})
68+
69+
self.assertTrue(po.fop_reached)
70+
po.button_approve()
71+
self.assertEqual(po.state, 'purchase')

purchase_fop_shipping/views/partner_view.xml

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<record model="ir.ui.view" id="origin_type_purchase_order_tree">
5+
<field name="model">purchase.order</field>
6+
<field name="type">tree</field>
7+
<field name="inherit_id" ref="purchase.purchase_order_tree"/>
8+
<field name="arch" type="xml">
9+
<xpath expr="//tree" position="attributes">
10+
<attribute name="decoration-danger">
11+
fop_reached == False
12+
</attribute>
13+
</xpath>
14+
<field name="origin" position="after">
15+
<field name="fop_reached" optional="show"/>
16+
</field>
17+
</field>
18+
</record>
19+
20+
<record model="ir.ui.view" id="purchase_order_delivery_paid_form_view_inherit">
21+
<field name="model">purchase.order</field>
22+
<field name="inherit_id" ref="purchase.purchase_order_form"/>
23+
<field name="type">form</field>
24+
<field name="arch" type="xml">
25+
<xpath expr="//field[@name='partner_ref']" position="after">
26+
<field name="force_order_under_fop"
27+
groups="purchase_fop_shipping.group_fop_shipping_purchase_manager"/>
28+
<field name="fop_shipping"/>
29+
</xpath>
30+
</field>
31+
</record>
32+
33+
</odoo>

purchase_fop_shipping/views/purchase_view.xml

-33
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<record model="ir.ui.view" id="res_partner_form_view_fop_shipping">
5+
<field name="model">res.partner</field>
6+
<field name="type">form</field>
7+
<field name="inherit_id" ref="account.view_partner_property_form"/>
8+
<field name="arch" type="xml">
9+
<xpath expr="//field[@name='property_supplier_payment_term_id']" position="after">
10+
<field name="fop_shipping"/>
11+
</xpath>
12+
</field>
13+
</record>
14+
15+
</odoo>

0 commit comments

Comments
 (0)