Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] purchase_start_end_dates: Migration to 17.0 #2513

Open
wants to merge 6 commits into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions purchase_start_end_dates/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
========================
Purchase Start End Dates
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:757c6e55d092de01f3be83c25a8b0ba88ac95b36e038e121d47765c40da46fa8
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/17.0/purchase_start_end_dates
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-17-0/purchase-workflow-17-0-purchase_start_end_dates
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module adds the fields *Start Date* and *End Date* on purchase
order lines (requied fields when the product has the *Must Have Start
and End Dates* property). You can also define a *Default Start Date* and
*Default End Date* on the purchase order; when set, these dates will be
used by default on new purchase order lines. Upon invoice creation, the
values of the start/end dates of the purchase order line are copied to
the start/end dates of invoice lines.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_start_end_dates%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* elego Software Solutions GmbH

Contributors
------------

- `Stesi Consulting <https://www.stesi.consulting>`__:

- Michele Di Croce

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

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/17.0/purchase_start_end_dates>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions purchase_start_end_dates/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions purchase_start_end_dates/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 elego Software Solutions, Germany (https://www.elegosoft.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Purchase Start End Dates",
"version": "17.0.1.0.0",
"category": "Purchase",
"license": "AGPL-3",
"summary": "Adds start date and end date on purchase order lines",
"author": "elego Software Solutions GmbH, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"depends": ["purchase", "account_invoice_start_end_dates"],
"data": [
"views/purchase_order.xml",
],
"installable": True,
}
101 changes: 101 additions & 0 deletions purchase_start_end_dates/i18n/purchase_start_end_dates.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * purchase_start_end_dates
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: purchase_start_end_dates
#: model:ir.model.fields,field_description:purchase_start_end_dates.field_purchase_order__default_end_date
msgid "Default End Date"
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model.fields,field_description:purchase_start_end_dates.field_purchase_order__default_start_date
msgid "Default Start Date"
msgstr ""

#. module: purchase_start_end_dates
#: code:addons/purchase_start_end_dates/models/purchase_order.py:23
#, python-format
msgid "Default Start Date should be before or be the same as Default End Date for purchase order '%s'."
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model.fields,field_description:purchase_start_end_dates.field_purchase_order_line__end_date
msgid "End Date"
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model.fields,help:purchase_start_end_dates.field_purchase_order_line__must_have_dates
msgid "If this option is active, the user will have to enter a Start Date and an End Date on the invoice lines that have this product."
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model,name:purchase_start_end_dates.model_account_invoice
msgid "Invoice"
msgstr ""

#. module: purchase_start_end_dates
#: code:addons/purchase_start_end_dates/models/purchase_order.py:111
#, python-format
msgid "Missing End Date for purchase order line with Product '%s'."
msgstr ""

#. module: purchase_start_end_dates
#: code:addons/purchase_start_end_dates/models/purchase_order.py:103
#, python-format
msgid "Missing Start Date for purchase order line with Product '%s'."
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model.fields,field_description:purchase_start_end_dates.field_purchase_order_line__must_have_dates
msgid "Must Have Start and End Dates"
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model.fields,field_description:purchase_start_end_dates.field_purchase_order_line__number_of_days
msgid "Number of Days"
msgstr ""

#. module: purchase_start_end_dates
#: code:addons/purchase_start_end_dates/models/purchase_order.py:81
#, python-format
msgid "On purchase order line with product '%s', the number of days is negative (%d) ; this is not allowed. The number of days has been forced to 1."
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model,name:purchase_start_end_dates.model_purchase_order
msgid "Purchase Order"
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model,name:purchase_start_end_dates.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: purchase_start_end_dates
#: model:ir.model.fields,field_description:purchase_start_end_dates.field_purchase_order_line__start_date
msgid "Start Date"
msgstr ""

#. module: purchase_start_end_dates
#: code:addons/purchase_start_end_dates/models/purchase_order.py:119
#, python-format
msgid "Start Date should be before or be the same as End Date for purchase order line with Product '%s'."
msgstr ""

#. module: purchase_start_end_dates
#: code:addons/purchase_start_end_dates/models/purchase_order.py:80
#, python-format
msgid "Wrong number of days"
msgstr ""

1 change: 1 addition & 0 deletions purchase_start_end_dates/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import purchase_order
164 changes: 164 additions & 0 deletions purchase_start_end_dates/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Copyright 2022 elego Software Solutions, Germany (https://www.elegosoft.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from dateutil.relativedelta import relativedelta

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


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

default_start_date = fields.Date()
default_end_date = fields.Date()

@api.constrains("default_start_date", "default_end_date")
def _check_default_start_end_dates(self):
if (
self.default_start_date
and self.default_end_date
and self.default_start_date > self.default_end_date
):
raise ValidationError(
_(
"Default Start Date should be before or be the "
"same as Default End Date for purchase order '%s'."
)
% self.display_name
)

@api.onchange("default_start_date")
def default_start_date_change(self):
if (
self.default_start_date
and self.default_end_date
and self.default_start_date > self.default_end_date
):
self.default_end_date = self.default_start_date

Check warning on line 38 in purchase_start_end_dates/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_start_end_dates/models/purchase_order.py#L38

Added line #L38 was not covered by tests

@api.onchange("default_end_date")
def default_end_date_change(self):
if (
self.default_start_date
and self.default_end_date
and self.default_start_date > self.default_end_date
):
self.default_start_date = self.default_end_date

Check warning on line 47 in purchase_start_end_dates/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_start_end_dates/models/purchase_order.py#L47

Added line #L47 was not covered by tests


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

start_date = fields.Date(readonly=True)
end_date = fields.Date(readonly=True)
number_of_days = fields.Integer(
compute="_compute_number_of_days",
inverse="_inverse_number_of_days",
string="Number of Days",
readonly=False,
store=True,
)
must_have_dates = fields.Boolean(related="product_id.must_have_dates")

def _prepare_account_move_line(self, move=False):
data = super()._prepare_account_move_line(move=move)
if self.product_id.must_have_dates:
data.update(
{
"start_date": self.start_date,
"end_date": self.end_date,
}
)
return data

@api.depends("start_date", "end_date")
def _compute_number_of_days(self):
for line in self:
days = False
if line.start_date and line.end_date:
days = (line.end_date - line.start_date).days + 1
line.number_of_days = days

@api.onchange("number_of_days")
def _inverse_number_of_days(self):
res = {"warning": {}}
for line in self:
if line.number_of_days < 0:
res["warning"]["title"] = _("Wrong number of days")
res["warning"]["message"] = _(

Check warning on line 89 in purchase_start_end_dates/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_start_end_dates/models/purchase_order.py#L88-L89

Added lines #L88 - L89 were not covered by tests
"On purchase order line with product '%(product_name)s', the "
"number of days is negative (%(number_of_days)s) ; this is not "
"allowed. The number of days has been forced to 1."
) % (
{
"product_name": line.product_id.display_name,
"number_of_days": line.number_of_days,
}
)
line.number_of_days = 1

Check warning on line 99 in purchase_start_end_dates/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_start_end_dates/models/purchase_order.py#L99

Added line #L99 was not covered by tests
if line.start_date:
line.end_date = line.start_date + relativedelta(
days=line.number_of_days - 1
)
elif line.end_date:
line.start_date = line.end_date - relativedelta(

Check warning on line 105 in purchase_start_end_dates/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_start_end_dates/models/purchase_order.py#L105

Added line #L105 was not covered by tests
days=line.number_of_days - 1
)
return res

@api.constrains("start_date", "end_date")
def _check_start_end_dates(self):
for line in self:
if line.must_have_dates:
if not line.start_date:
raise ValidationError(
_(
"Missing Start Date for purchase order line with "
"Product '%s'."
)
% (line.product_id.name)
)
if not line.end_date:
raise ValidationError(
_(
"Missing End Date for purchase order line with "
"Product '%s'."
)
% (line.product_id.name)
)
if line.start_date > line.end_date:
raise ValidationError(
_(
"Start Date should be before or be the same as "
"End Date for purchase order line with Product '%s'."
)
% (line.product_id.name)
)

@api.onchange("end_date")
def end_date_change(self):
if self.end_date:
if self.start_date and self.start_date > self.end_date:
self.start_date = self.end_date

@api.onchange("start_date")
def start_date_change(self):
if self.start_date:
if self.end_date and self.start_date > self.end_date:
self.end_date = self.start_date

@api.onchange("product_id")
def start_end_dates_product_id_change(self):
if self.product_id.must_have_dates:
if self.order_id.default_start_date:
self.start_date = self.order_id.default_start_date
else:
self.start_date = False

Check warning on line 157 in purchase_start_end_dates/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_start_end_dates/models/purchase_order.py#L157

Added line #L157 was not covered by tests
if self.order_id.default_end_date:
self.end_date = self.order_id.default_end_date
else:
self.end_date = False

Check warning on line 161 in purchase_start_end_dates/models/purchase_order.py

View check run for this annotation

Codecov / codecov/patch

purchase_start_end_dates/models/purchase_order.py#L161

Added line #L161 was not covered by tests
else:
self.start_date = False
self.end_date = False
3 changes: 3 additions & 0 deletions purchase_start_end_dates/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions purchase_start_end_dates/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Stesi Consulting](https://www.stesi.consulting):
- Michele Di Croce
7 changes: 7 additions & 0 deletions purchase_start_end_dates/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module adds the fields *Start Date* and *End Date* on purchase order
lines (requied fields when the product has the *Must Have Start and End
Dates* property). You can also define a *Default Start Date* and
*Default End Date* on the purchase order; when set, these dates will be used
by default on new purchase order lines. Upon invoice creation, the values of
the start/end dates of the purchase order line are copied to the start/end
dates of invoice lines.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading