changeset d51b25a14a7b in modules/project_invoice:default
details: 
https://hg.tryton.org/modules/project_invoice?cmd=changeset;node=d51b25a14a7b
description:
        Add date up to which to invoice timesheet

        issue9761
        review304631002
diffstat:

 CHANGELOG                                    |   2 ++
 project.py                                   |  22 +++++++++++++++++++++-
 tests/scenario_project_invoice_timesheet.rst |  20 +++++++++++++++++++-
 view/work_form.xml                           |   4 ++++
 4 files changed, 46 insertions(+), 2 deletions(-)

diffs (122 lines):

diff -r d47145a53da1 -r d51b25a14a7b CHANGELOG
--- a/CHANGELOG Sun Nov 15 18:01:52 2020 +0100
+++ b/CHANGELOG Fri Nov 27 22:49:37 2020 +0100
@@ -1,3 +1,5 @@
+* Add date up to which to invoice timesheet
+
 Version 5.8.0 - 2020-11-02
 * Bug fixes (see mercurial logs for details)
 * Remove support for Python 3.5
diff -r d47145a53da1 -r d51b25a14a7b project.py
--- a/project.py        Sun Nov 15 18:01:52 2020 +0100
+++ b/project.py        Fri Nov 27 22:49:37 2020 +0100
@@ -207,6 +207,17 @@
 
 class Timesheet:
 
+    project_invoice_timesheet_up_to = fields.Date(
+        "Invoice up to",
+        states={
+            'invisible': Eval('project_invoice_method') != 'timesheet',
+            },
+        depends=['project_invoice_method'],
+        help="Limits which timesheet lines get invoiced to "
+        "only those before the date.")
+    invoice_timesheet_up_to = fields.Function(fields.Date(
+            "Invoice up to"), 'on_change_with_invoice_timesheet_up_to')
+
     @classmethod
     def __setup__(cls):
         super().__setup__()
@@ -221,6 +232,14 @@
         if 'invoice_method' not in cls.product.depends:
             cls.product.depends.append('invoice_method')
 
+    @fields.depends('type', 'project_invoice_timesheet_up_to',
+        'parent', '_parent_parent.invoice_timesheet_up_to')
+    def on_change_with_invoice_timesheet_up_to(self, name=None):
+        if self.type == 'project':
+            return self.project_invoice_timesheet_up_to
+        elif self.parent:
+            return self.parent.invoice_timesheet_up_to
+
     @classmethod
     def _get_quantity_to_invoice_timesheet(cls, works):
         pool = Pool()
@@ -311,10 +330,11 @@
         except AttributeError:
             origins = []
         if self.invoice_method == 'timesheet':
+            up_to = self.invoice_timesheet_up_to or datetime.date.max
             origins.extend(
                 l for tw in self.timesheet_works
                 for l in tw.timesheet_lines
-                if not l.invoice_line)
+                if not l.invoice_line and l.date <= up_to)
         return origins
 
 
diff -r d47145a53da1 -r d51b25a14a7b 
tests/scenario_project_invoice_timesheet.rst
--- a/tests/scenario_project_invoice_timesheet.rst      Sun Nov 15 18:01:52 
2020 +0100
+++ b/tests/scenario_project_invoice_timesheet.rst      Fri Nov 27 22:49:37 
2020 +0100
@@ -16,6 +16,7 @@
     >>> from trytond.modules.account_invoice.tests.tools import \
     ...     create_payment_term
     >>> today = datetime.date.today()
+    >>> yesterday = today - datetime.timedelta(days=1)
 
 Activate modules::
 
@@ -133,11 +134,13 @@
 
     >>> TimesheetLine = Model.get('timesheet.line')
     >>> line = TimesheetLine()
+    >>> line.date = yesterday
     >>> line.employee = employee
     >>> line.duration = datetime.timedelta(hours=3)
     >>> line.work, = task.timesheet_works
     >>> line.save()
     >>> line = TimesheetLine()
+    >>> line.date = today
     >>> line.employee = employee
     >>> line.duration = datetime.timedelta(hours=2)
     >>> line.work, = project.timesheet_works
@@ -151,8 +154,23 @@
     >>> project.invoiced_amount
     Decimal('0.00')
 
-Invoice project::
+Invoice project up to yesterday::
 
+    >>> set_user(project_user)
+    >>> project.project_invoice_timesheet_up_to = yesterday
+    >>> project.save()
+    >>> set_user(project_invoice_user)
+    >>> project.click('invoice')
+    >>> project.amount_to_invoice
+    Decimal('40.00')
+    >>> project.invoiced_amount
+    Decimal('60.00')
+
+Invoice all project::
+
+    >>> set_user(project_user)
+    >>> project.project_invoice_timesheet_up_to = None
+    >>> project.save()
     >>> set_user(project_invoice_user)
     >>> project.click('invoice')
     >>> project.amount_to_invoice
diff -r d47145a53da1 -r d51b25a14a7b view/work_form.xml
--- a/view/work_form.xml        Sun Nov 15 18:01:52 2020 +0100
+++ b/view/work_form.xml        Fri Nov 27 22:49:37 2020 +0100
@@ -8,6 +8,10 @@
         <label name="project_invoice_method"/>
         <field name="project_invoice_method"/>
     </xpath>
+    <xpath expr="//field[@name='list_price']" position="after">
+        <label name="project_invoice_timesheet_up_to"/>
+        <field name="project_invoice_timesheet_up_to"/>
+    </xpath>
     <xpath 
expr="/form/notebook/page[@id='general']/field[@name='total_effort']" 
position="after">
         <label name="amount_to_invoice"/>
         <field name="amount_to_invoice" symbol="currency"/>

Reply via email to