Skip to content

Commit 7ca6294

Browse files
NuriaXifreDavidJForgeFlow
authored andcommitted
[IMP] : black, isort, prettier
1 parent 68d52f3 commit 7ca6294

12 files changed

+146
-133
lines changed

supplier_calendar/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
22
from . import models
3-

supplier_calendar/__manifest__.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,14 @@
33
{
44
"name": "Supplier Calendar",
55
"summary": "Supplier Calendar",
6-
'version': '12.0.1.0.0',
6+
"version": "12.0.1.0.0",
77
"category": "Purchase Management",
8-
"author": "ForgeFlow,"
9-
"Odoo Community Association (OCA)",
8+
"author": "ForgeFlow," "Odoo Community Association (OCA)",
109
"maintainers": ["NuriaMForgeFlow"],
1110
"license": "LGPL-3",
12-
'application': False,
13-
'installable': True,
14-
'auto_install': False,
15-
"depends": [
16-
"purchase_stock",
17-
"resource",
18-
],
19-
"data": [
20-
'views/res_partner_view.xml',
21-
'views/product_view.xml'
22-
],
11+
"application": False,
12+
"installable": True,
13+
"auto_install": False,
14+
"depends": ["purchase_stock", "resource",],
15+
"data": ["views/res_partner_view.xml", "views/product_view.xml"],
2316
}

supplier_calendar/models/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
from . import product
44
from . import stock_rule
55
from . import purchase
6-

supplier_calendar/models/product.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Copyright 2020 ForgeFlow S.L.
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import models, fields
4+
from odoo import fields, models
55

66

77
class ProductSupplierInfo(models.Model):
88
_inherit = "product.supplierinfo"
99

1010
delay_calendar_type = fields.Selection(
11-
related='name.delay_calendar_type',
12-
readonly=True)
11+
related="name.delay_calendar_type", readonly=True
12+
)

supplier_calendar/models/purchase.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# Copyright 2020 ForgeFlow S.L.
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
33

4-
from odoo import models, api
54
from datetime import datetime
65

6+
from odoo import api, models
7+
78

89
class PurchaseOrderLine(models.Model):
9-
_inherit = 'purchase.order.line'
10+
_inherit = "purchase.order.line"
1011

1112
@api.model
1213
def _get_date_planned(self, seller, po=False):
13-
date_planned = super(PurchaseOrderLine, self)._get_date_planned(seller,
14-
po)
14+
date_planned = super(PurchaseOrderLine, self)._get_date_planned(seller, po)
1515
if seller.name.factory_calendar_id:
1616
date_order = po.date_order if po else self.order_id.date_order
1717
if date_order:
18-
date_planned = seller.name.supplier_plan_days(date_order,
19-
seller.delay)
18+
date_planned = seller.name.supplier_plan_days(date_order, seller.delay)
2019
else:
21-
date_planned = seller.name.supplier_plan_days(datetime.today(),
22-
seller.delay)
20+
date_planned = seller.name.supplier_plan_days(
21+
datetime.today(), seller.delay
22+
)
2323
return date_planned

supplier_calendar/models/res_partner.py

+13-12
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33

44
from datetime import datetime, timedelta
55

6-
from odoo import models, api, fields
6+
from odoo import api, fields, models
77

88

99
class ResPartner(models.Model):
10-
_inherit = 'res.partner'
10+
_inherit = "res.partner"
1111

12-
factory_calendar_id = fields.Many2one(comodel_name='resource.calendar')
13-
delay_calendar_type = fields.Selection([
14-
('natural', 'Natural days'),
15-
('supplier_calendar', 'Supplier Calendar'),
16-
], default='natural', required=True)
12+
factory_calendar_id = fields.Many2one(comodel_name="resource.calendar")
13+
delay_calendar_type = fields.Selection(
14+
[("natural", "Natural days"), ("supplier_calendar", "Supplier Calendar"),],
15+
default="natural",
16+
required=True,
17+
)
1718

18-
@api.onchange('delay_calendar_type')
19+
@api.onchange("delay_calendar_type")
1920
def _onchange_delay_calendar_type(self):
2021
for rec in self:
21-
if rec.delay_calendar_type == 'natural':
22+
if rec.delay_calendar_type == "natural":
2223
rec.factory_calendar_id = False
2324

2425
def supplier_plan_days(self, date_from, delta):
@@ -42,9 +43,9 @@ def supplier_plan_days(self, date_from, delta):
4243
else:
4344
# We force the date planned at the end of the day.
4445
dt_planned = date_from.replace(hour=23)
45-
date_result = self.factory_calendar_id.plan_days(delta,
46-
dt_planned,
47-
compute_leaves=True)
46+
date_result = self.factory_calendar_id.plan_days(
47+
delta, dt_planned, compute_leaves=True
48+
)
4849
else:
4950
date_result = date_from + timedelta(days=delta)
5051
return date_result

supplier_calendar/models/stock_rule.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@
55

66

77
class StockRule(models.Model):
8-
_inherit = 'stock.rule'
8+
_inherit = "stock.rule"
99

10-
def _get_purchase_order_date(self, product_id, product_qty, product_uom,
11-
values, partner, schedule_date):
10+
def _get_purchase_order_date(
11+
self, product_id, product_qty, product_uom, values, partner, schedule_date
12+
):
1213
res = super()._get_purchase_order_date(
13-
product_id,
14-
product_qty, product_uom,
15-
values, partner, schedule_date)
16-
seller = product_id.with_context(force_company=values[
17-
'company_id'].id)._select_seller(partner_id=partner,
18-
quantity=product_qty,
19-
date=schedule_date and
20-
schedule_date.date(),
21-
uom_id=product_uom)
14+
product_id, product_qty, product_uom, values, partner, schedule_date
15+
)
16+
seller = product_id.with_context(
17+
force_company=values["company_id"].id
18+
)._select_seller(
19+
partner_id=partner,
20+
quantity=product_qty,
21+
date=schedule_date and schedule_date.date(),
22+
uom_id=product_uom,
23+
)
2224
if seller:
2325
delay = -1 * seller.delay
2426
res = seller.name.supplier_plan_days(schedule_date, delay)

supplier_calendar/readme/CONFIGURE.rst

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66
* Go to *Contacts > Sales&Purchases > Purchase > Delay Calendar Type*
77
and assign Supplier Calendar and in *Factory Closing Days* assign the
88
Resource Calendar desired.
9-

supplier_calendar/readme/USAGE.rst

-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@ natural days. THis module adds the possibility of expressing the lead time
66
of a vendor in his own calendar. This way, the order dates of purchase
77
orders and the scheduled dates of receipts will only take into account the
88
supplier working days.
9-

supplier_calendar/tests/test_supplier_calendar.py

+86-67
Original file line numberDiff line numberDiff line change
@@ -6,87 +6,107 @@
66

77

88
class TestStockWarehouseCalendar(TransactionCase):
9-
109
def setUp(self):
1110
super(TestStockWarehouseCalendar, self).setUp()
12-
self.move_obj = self.env['stock.move']
13-
self.company = self.env.ref('base.main_company')
14-
self.company_partner = self.env.ref('base.main_partner')
15-
self.calendar = self.env.ref('resource.resource_calendar_std')
16-
self.supplier_info = self.env['product.supplierinfo']
17-
self.PurchaseOrder = self.env['purchase.order']
18-
self.PurchaseOrderLine = self.env['purchase.order.line']
19-
self.stock_location = self.env['ir.model.data'].xmlid_to_object(
20-
'stock.stock_location_stock')
21-
self.customer_location = self.env['ir.model.data'].xmlid_to_object(
22-
'stock.stock_location_customers')
23-
self.picking_type_out = self.env['ir.model.data'].xmlid_to_object(
24-
'stock.picking_type_out')
25-
self.route_buy = self.env.ref('purchase_stock.route_warehouse0_buy').id
11+
self.move_obj = self.env["stock.move"]
12+
self.company = self.env.ref("base.main_company")
13+
self.company_partner = self.env.ref("base.main_partner")
14+
self.calendar = self.env.ref("resource.resource_calendar_std")
15+
self.supplier_info = self.env["product.supplierinfo"]
16+
self.PurchaseOrder = self.env["purchase.order"]
17+
self.PurchaseOrderLine = self.env["purchase.order.line"]
18+
self.stock_location = self.env["ir.model.data"].xmlid_to_object(
19+
"stock.stock_location_stock"
20+
)
21+
self.customer_location = self.env["ir.model.data"].xmlid_to_object(
22+
"stock.stock_location_customers"
23+
)
24+
self.picking_type_out = self.env["ir.model.data"].xmlid_to_object(
25+
"stock.picking_type_out"
26+
)
27+
self.route_buy = self.env.ref("purchase_stock.route_warehouse0_buy").id
2628

2729
# Create product
28-
self.product = self.env['product.product'].create({
29-
'name': 'test product',
30-
'default_code': 'PRD',
31-
'type': 'product',
32-
'route_ids': [(4, self.ref('stock.route_warehouse0_mto')),
33-
(4, self.ref('purchase_stock.route_warehouse0_buy'))]
34-
})
30+
self.product = self.env["product.product"].create(
31+
{
32+
"name": "test product",
33+
"default_code": "PRD",
34+
"type": "product",
35+
"route_ids": [
36+
(4, self.ref("stock.route_warehouse0_mto")),
37+
(4, self.ref("purchase_stock.route_warehouse0_buy")),
38+
],
39+
}
40+
)
3541

3642
# Partner and Supplierinfo
37-
self.company_partner.write({
38-
'delay_calendar_type': 'supplier_calendar',
39-
'factory_calendar_id': self.calendar.id
40-
41-
})
42-
self.seller_01 = self.supplier_info.create({
43-
'name': self.company_partner.id,
44-
"product_id": self.product.id,
45-
'product_tmpl_id': self.product.product_tmpl_id.id,
46-
'delay': 3
47-
})
43+
self.company_partner.write(
44+
{
45+
"delay_calendar_type": "supplier_calendar",
46+
"factory_calendar_id": self.calendar.id,
47+
}
48+
)
49+
self.seller_01 = self.supplier_info.create(
50+
{
51+
"name": self.company_partner.id,
52+
"product_id": self.product.id,
53+
"product_tmpl_id": self.product.product_tmpl_id.id,
54+
"delay": 3,
55+
}
56+
)
4857

4958
def test_01_purchase_order_with_supplier_calendar(self):
5059
# Create a customer picking
51-
customer_picking = self.env['stock.picking'].create({
52-
'location_id': self.stock_location.id,
53-
'location_dest_id': self.customer_location.id,
54-
'partner_id': self.company_partner.id,
55-
'picking_type_id': self.picking_type_out.id,
56-
})
60+
customer_picking = self.env["stock.picking"].create(
61+
{
62+
"location_id": self.stock_location.id,
63+
"location_dest_id": self.customer_location.id,
64+
"partner_id": self.company_partner.id,
65+
"picking_type_id": self.picking_type_out.id,
66+
}
67+
)
5768

58-
customer_move = self.env['stock.move'].create({
59-
'name': 'move out',
60-
'location_id': self.stock_location.id,
61-
'location_dest_id': self.customer_location.id,
62-
'product_id': self.product.id,
63-
'product_uom': self.product.uom_id.id,
64-
'product_uom_qty': 80.0,
65-
'procure_method': 'make_to_order',
66-
'picking_id': customer_picking.id,
67-
'date_expected': '2097-01-14 09:00:00' # Monday
68-
})
69+
customer_move = self.env["stock.move"].create(
70+
{
71+
"name": "move out",
72+
"location_id": self.stock_location.id,
73+
"location_dest_id": self.customer_location.id,
74+
"product_id": self.product.id,
75+
"product_uom": self.product.uom_id.id,
76+
"product_uom_qty": 80.0,
77+
"procure_method": "make_to_order",
78+
"picking_id": customer_picking.id,
79+
"date_expected": "2097-01-14 09:00:00", # Monday
80+
}
81+
)
6982

7083
customer_move._action_confirm()
7184

72-
purchase_order = self.env['purchase.order'].search(
73-
[('partner_id', '=', self.company_partner.id)])
74-
self.assertTrue(purchase_order, 'No purchase order created.')
85+
purchase_order = self.env["purchase.order"].search(
86+
[("partner_id", "=", self.company_partner.id)]
87+
)
88+
self.assertTrue(purchase_order, "No purchase order created.")
7589
date_order = fields.Date.to_date(purchase_order.date_order)
76-
wednesday = fields.Date.to_date('2097-01-09 09:00:00')
90+
wednesday = fields.Date.to_date("2097-01-09 09:00:00")
7791
self.assertEqual(date_order, wednesday) # Wednesday
7892

7993
def test_02_purchase_order_supplier_calendar_global_leaves(self):
8094
# Global leaves
81-
self.calendar.write({
82-
'global_leave_ids': [
83-
(0, False, {
84-
'name': 'Test',
85-
'date_from': '2097-01-14', # Monday
86-
'date_to': '2097-01-19', # Saturday
87-
}),
88-
],
89-
})
95+
self.calendar.write(
96+
{
97+
"global_leave_ids": [
98+
(
99+
0,
100+
False,
101+
{
102+
"name": "Test",
103+
"date_from": "2097-01-14", # Monday
104+
"date_to": "2097-01-19", # Saturday
105+
},
106+
),
107+
],
108+
}
109+
)
90110

91111
reference = "2097-01-14 09:00:00" # Monday
92112
# With calendar
@@ -97,10 +117,9 @@ def test_02_purchase_order_supplier_calendar_global_leaves(self):
97117
result = self.company_partner.supplier_plan_days(reference_2, 3).date()
98118
self.assertEquals(result, next_wednesday)
99119
# Without calendar
100-
self.company_partner.write({
101-
'delay_calendar_type': 'natural',
102-
'factory_calendar_id': False
103-
})
120+
self.company_partner.write(
121+
{"delay_calendar_type": "natural", "factory_calendar_id": False}
122+
)
104123
reference_3 = "2097-01-25 12:00:00" # friday
105124
result = self.company_partner.supplier_plan_days(reference_3, 3).date()
106125
monday = fields.Date.to_date("2097-01-28")

supplier_calendar/views/product_view.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<!-- Copyright 2020 ForgeFlow S.L.
33
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
44
<odoo>
5-
<record id="product_supplierinfo_form_view" model="ir.ui.view">
5+
<record id="product_supplierinfo_form_view" model="ir.ui.view">
66
<field name="name">product.supplierinfo.form.view</field>
77
<field name="model">product.supplierinfo</field>
8-
<field name="inherit_id" ref="product.product_supplierinfo_form_view"/>
8+
<field name="inherit_id" ref="product.product_supplierinfo_form_view" />
99
<field name="arch" type="xml">
1010
<xpath expr="//field[@name='delay']/../../div" position="after">
11-
<field name="delay_calendar_type"/>
11+
<field name="delay_calendar_type" />
1212
</xpath>
1313
</field>
1414
</record>

0 commit comments

Comments
 (0)