Skip to content

Commit 6135a7b

Browse files
NuriaXifreDavidJForgeFlow
authored andcommitted
[12.0][ADD]supplier_calendar
1 parent f23bc96 commit 6135a7b

18 files changed

+885
-0
lines changed

supplier_calendar/README.rst

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
=================
2+
Supplier Calendar
3+
=================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
15+
:alt: License: LGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
17+
:target: https://github.com/OCA/purchase-workflow/tree/12.0/supplier_calendar
18+
:alt: OCA/purchase-workflow
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/purchase-workflow-12-0/purchase-workflow-12-0-supplier_calendar
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/142/12.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This module adds a Calendar to the ResPartner model. This calendar can then
29+
used as the basis of the proper computation of start/end dates based on the
30+
delivery lead time of the supplier in this and other modules.
31+
32+
In this module, the calendar is considered in the computation of the schedules
33+
date of a stock picking and in the order date of a purchase order.
34+
35+
**Table of contents**
36+
37+
.. contents::
38+
:local:
39+
40+
Configuration
41+
=============
42+
43+
* Go to *Settings* and activate the developer mode.
44+
45+
* Go to *Settings > Technical > Resource > Working Time* and define your
46+
resource calendar.
47+
48+
* Go to *Contacts > Sales&Purchases > Purchase > Delay Calendar Type*
49+
and assign Supplier Calendar and in *Factory Closing Days* assign the
50+
Resource Calendar desired.
51+
52+
53+
Usage
54+
=====
55+
56+
When a picking is created from a purchase order of a supplier, the lead
57+
time used to calculate the scheduled date is computed in natural days. At the
58+
same time, when a purchase order is created due to a a procurement
59+
evaluation, its order date is also computed considering the lead time in
60+
natural days. THis module adds the possibility of expressing the lead time
61+
of a vendor in his own calendar. This way, the order dates of purchase
62+
orders and the scheduled dates of receipts will only take into account the
63+
supplier working days.
64+
65+
66+
Bug Tracker
67+
===========
68+
69+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
70+
In case of trouble, please check there if your issue has already been reported.
71+
If you spotted it first, help us smashing it by providing a detailed and welcomed
72+
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20supplier_calendar%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
73+
74+
Do not contact contributors directly about support or help with technical issues.
75+
76+
Credits
77+
=======
78+
79+
Authors
80+
~~~~~~~
81+
82+
* ForgeFlow
83+
84+
Contributors
85+
~~~~~~~~~~~~
86+
87+
* Núria Martín <nuria.martin@forgeflow.com>
88+
* Jordi Ballester <jordi.ballester@forgeflow.com>
89+
* Lois Rilo <lois.rilo@eforgeflow>
90+
91+
Maintainers
92+
~~~~~~~~~~~
93+
94+
This module is maintained by the OCA.
95+
96+
.. image:: https://odoo-community.org/logo.png
97+
:alt: Odoo Community Association
98+
:target: https://odoo-community.org
99+
100+
OCA, or the Odoo Community Association, is a nonprofit organization whose
101+
mission is to support the collaborative development of Odoo features and
102+
promote its widespread use.
103+
104+
.. |maintainer-Nuria Martin <nuria.martin@forgeflow.com>| image:: https://github.com/Nuria Martin <nuria.martin@forgeflow.com>.png?size=40px
105+
:target: https://github.com/Nuria Martin <nuria.martin@forgeflow.com>
106+
:alt: Nuria Martin <nuria.martin@forgeflow.com>
107+
.. |maintainer-Jordi Ballester <jordi.ballester@forgeflow.com>| image:: https://github.com/Jordi Ballester <jordi.ballester@forgeflow.com>.png?size=40px
108+
:target: https://github.com/Jordi Ballester <jordi.ballester@forgeflow.com>
109+
:alt: Jordi Ballester <jordi.ballester@forgeflow.com>
110+
.. |maintainer-Lois Rilo <lois.rilo@forgeflow.com>| image:: https://github.com/Lois Rilo <lois.rilo@forgeflow.com>.png?size=40px
111+
:target: https://github.com/Lois Rilo <lois.rilo@forgeflow.com>
112+
:alt: Lois Rilo <lois.rilo@forgeflow.com>
113+
114+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
115+
116+
|maintainer-Nuria Martin <nuria.martin@forgeflow.com>| |maintainer-Jordi Ballester <jordi.ballester@forgeflow.com>| |maintainer-Lois Rilo <lois.rilo@forgeflow.com>|
117+
118+
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/12.0/supplier_calendar>`_ project on GitHub.
119+
120+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

supplier_calendar/__init__.py

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

supplier_calendar/__manifest__.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2020 ForgeFlow
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
3+
{
4+
"name": "Supplier Calendar",
5+
"summary": "Supplier Calendar",
6+
'version': '12.0.1.0.0',
7+
"category": "Purchase Management",
8+
"author": "ForgeFlow,"
9+
"Odoo Community Association (OCA)",
10+
"maintainers": ["NuriaMForgeFlow"],
11+
"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+
],
23+
}

supplier_calendar/models/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
2+
from . import res_partner
3+
from . import product
4+
from . import stock_rule
5+
from . import purchase
6+

supplier_calendar/models/product.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2020 ForgeFlow S.L.
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import models, fields
5+
6+
7+
class ProductSupplierInfo(models.Model):
8+
_inherit = "product.supplierinfo"
9+
10+
delay_calendar_type = fields.Selection(
11+
related='name.delay_calendar_type',
12+
readonly=True)

supplier_calendar/models/purchase.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2020 ForgeFlow S.L.
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
3+
4+
from odoo import models, api
5+
from datetime import datetime
6+
7+
8+
class PurchaseOrderLine(models.Model):
9+
_inherit = 'purchase.order.line'
10+
11+
@api.model
12+
def _get_date_planned(self, seller, po=False):
13+
date_planned = super(PurchaseOrderLine, self)._get_date_planned(seller,
14+
po)
15+
if seller.name.factory_calendar_id:
16+
date_order = po.date_order if po else self.order_id.date_order
17+
if date_order:
18+
date_planned = seller.name.supplier_plan_days(date_order,
19+
seller.delay)
20+
else:
21+
date_planned = seller.name.supplier_plan_days(datetime.today(),
22+
seller.delay)
23+
return date_planned
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Copyright 2020 ForgeFlow S.L.
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
3+
4+
from datetime import datetime, timedelta
5+
6+
from odoo import models, api, fields
7+
8+
9+
class ResPartner(models.Model):
10+
_inherit = 'res.partner'
11+
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)
17+
18+
@api.onchange('delay_calendar_type')
19+
def _onchange_delay_calendar_type(self):
20+
for rec in self:
21+
if rec.delay_calendar_type == 'natural':
22+
rec.factory_calendar_id = False
23+
24+
def supplier_plan_days(self, date_from, delta):
25+
"""Helper method to calculate supplier delay based on its
26+
working days (if set).
27+
28+
:param datetime date_from: reference date.
29+
:param integer delta: delay established.
30+
:return: datetime: resulting date.
31+
"""
32+
self.ensure_one()
33+
if not isinstance(date_from, datetime):
34+
date_from = fields.Datetime.to_datetime(date_from)
35+
if delta == 0:
36+
return date_from
37+
if self.factory_calendar_id:
38+
if delta < 0:
39+
# We force the date planned to be at the beginning of the day.
40+
# So no work intervals are found in the reference date.
41+
dt_planned = date_from.replace(hour=0)
42+
else:
43+
# We force the date planned at the end of the day.
44+
dt_planned = date_from.replace(hour=23)
45+
date_result = self.factory_calendar_id.plan_days(delta,
46+
dt_planned,
47+
compute_leaves=True)
48+
else:
49+
date_result = date_from + timedelta(days=delta)
50+
return date_result
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2020 ForgeFlow S.L.
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
3+
4+
from odoo import models
5+
6+
7+
class StockRule(models.Model):
8+
_inherit = 'stock.rule'
9+
10+
def _get_purchase_order_date(self, product_id, product_qty, product_uom,
11+
values, partner, schedule_date):
12+
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)
22+
if seller:
23+
delay = -1 * seller.delay
24+
res = seller.name.supplier_plan_days(schedule_date, delay)
25+
return res
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* Go to *Settings* and activate the developer mode.
2+
3+
* Go to *Settings > Technical > Resource > Working Time* and define your
4+
resource calendar.
5+
6+
* Go to *Contacts > Sales&Purchases > Purchase > Delay Calendar Type*
7+
and assign Supplier Calendar and in *Factory Closing Days* assign the
8+
Resource Calendar desired.
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
* Núria Martín <nuria.martin@forgeflow.com>
3+
* Jordi Ballester <jordi.ballester@forgeflow.com>
4+
* Lois Rilo <lois.rilo@eforgeflow>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This module adds a Calendar to the ResPartner model. This calendar can then
2+
used as the basis of the proper computation of start/end dates based on the
3+
delivery lead time of the supplier in this and other modules.
4+
5+
In this module, the calendar is considered in the computation of the schedules
6+
date of a stock picking and in the order date of a purchase order.

supplier_calendar/readme/USAGE.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
When a picking is created from a purchase order of a supplier, the lead
2+
time used to calculate the scheduled date is computed in natural days. At the
3+
same time, when a purchase order is created due to a a procurement
4+
evaluation, its order date is also computed considering the lead time in
5+
natural days. THis module adds the possibility of expressing the lead time
6+
of a vendor in his own calendar. This way, the order dates of purchase
7+
orders and the scheduled dates of receipts will only take into account the
8+
supplier working days.
9+
9.23 KB
Loading

0 commit comments

Comments
 (0)