Skip to content

Commit

Permalink
[MIG] product_template_multi_link_date_span: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thienvh332 committed Dec 4, 2024
1 parent 03dc9db commit 358a509
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 23 deletions.
4 changes: 4 additions & 0 deletions product_template_multi_link_date_span/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Contributors
- Trobz

- Dung Tran <dungtd@trobz.com>
- Thien Vo <thienvh@trobz.com>

- Simone Orsi <simahawk@gmail.com>

Expand All @@ -72,6 +73,9 @@ The development of this module has been financially supported by:

- Camptocamp

The migration of this module from 14.0 to 18.0 was financially supported
by Camptocamp.

Maintainers
-----------

Expand Down
2 changes: 1 addition & 1 deletion product_template_multi_link_date_span/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Product Template Multi Link With Dates",
"summary": "Add an optional date span for when a link is active.",
"version": "14.0.1.1.0",
"version": "18.0.1.0.0",
"category": "Sale",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# @author Simone Orsi <simahawk@gmail.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, exceptions, fields, models
from odoo import api, exceptions, fields, models


class ProductTemplateLink(models.Model):
Expand All @@ -16,19 +16,22 @@ class ProductTemplateLink(models.Model):

@api.depends("date_start", "date_end", "type_id.limited_by_dates")
def _compute_is_link_active(self):
super()._compute_is_link_active()
res = super()._compute_is_link_active()
today = fields.Date.today()
for record in self:
if record.limited_by_dates:
record.is_link_active = (
(record.date_start or today) <= today <= (record.date_end or today)
)
return res

@api.constrains("type_id", "date_start")
def _check_mandatory_date_start(self):
for rec in self:
if rec.mandatory_date_start and not rec.date_start:
raise exceptions.UserError(
_("A start date is required according to link type: %s")
% rec.type_id.name
self.env._(
"A start date is required according to link type: %s",
rec.type_id.name,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

- Trobz
- Dung Tran \<<dungtd@trobz.com>\>
- Thien Vo \<<thienvh@trobz.com>\>

- Simone Orsi \<<simahawk@gmail.com>\>
2 changes: 2 additions & 0 deletions product_template_multi_link_date_span/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
The development of this module has been financially supported by:

- Camptocamp

The migration of this module from 14.0 to 18.0 was financially supported by Camptocamp.
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<li>Thierry Ducrest &lt;<a class="reference external" href="mailto:thierry.ducrest&#64;camptocamp.com">thierry.ducrest&#64;camptocamp.com</a>&gt;</li>
<li>Trobz<ul>
<li>Dung Tran &lt;<a class="reference external" href="mailto:dungtd&#64;trobz.com">dungtd&#64;trobz.com</a>&gt;</li>
<li>Thien Vo &lt;<a class="reference external" href="mailto:thienvh&#64;trobz.com">thienvh&#64;trobz.com</a>&gt;</li>
</ul>
</li>
<li>Simone Orsi &lt;<a class="reference external" href="mailto:simahawk&#64;gmail.com">simahawk&#64;gmail.com</a>&gt;</li>
Expand All @@ -418,6 +419,8 @@ <h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<ul class="simple">
<li>Camptocamp</li>
</ul>
<p>The migration of this module from 14.0 to 18.0 was financially supported
by Camptocamp.</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from freezegun import freeze_time

from odoo import exceptions
from odoo.tests.common import SavepointCase
from odoo.tests.common import TransactionCase


@freeze_time("2020-07-29")
class TestProductTemplateLinkDateSpan(SavepointCase):
class TestProductTemplateLinkDateSpan(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" ?>
<odoo>
<record id="product_template_link_type_tree_view" model="ir.ui.view">
<field name="name">product.template.link.type.tree.date.span</field>
<field name="name">product.template.link.type.list.date.span</field>
<field name="model">product.template.link.type</field>
<field
name="inherit_id"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
<?xml version="1.0" ?>
<odoo>
<record id="product_template_link_tree" model="ir.ui.view">
<field name="name">product.template.link.tree.date.span</field>
<field name="name">product.template.link.list.date.span</field>
<field name="model">product.template.link</field>
<field
name="inherit_id"
ref="product_template_multi_link.product_template_link_tree"
/>
<field name="arch" type="xml">
<field name="right_product_tmpl_id" position="after">
<field name="mandatory_date_start" invisible="1" />
<field
name="date_start"
attrs="{'required': [('mandatory_date_start', '=', True)]}"
/>
<field name="date_start" required="mandatory_date_start" />
<field name="date_end" />
</field>
</field>
Expand All @@ -27,16 +23,9 @@
/>
<field name="arch" type="xml">
<group name="main" position="inside">
<field name="limited_by_dates" invisible="1" />
<group
name="dates"
attrs="{'invisible': [('limited_by_dates', '=', False)]}"
>
<group name="dates" invisible="not limited_by_dates">
<field name="mandatory_date_start" />
<field
name="date_start"
attrs="{'required': [('mandatory_date_start', '=', True)]}"
/>
<field name="date_start" required="mandatory_date_start" />
<field name="date_end" />
</group>
</group>
Expand Down

0 comments on commit 358a509

Please sign in to comment.