From a66dfe96c43ee33844141f007c04def6c9bfcc42 Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Tue, 27 Feb 2018 19:19:06 +0100 Subject: [PATCH] [IMP] sale_order_invoicing_finished_task (#556) When the product has an invoicing policy Ordered Quantity, setting the task as Invoiceable will set the delivered qty on the sale order line to the ordered quantity. --- sale_order_invoicing_finished_task/README.rst | 4 ++++ .../__manifest__.py | 2 +- sale_order_invoicing_finished_task/i18n/fr.po | 15 ++++++++------- .../models/project.py | 9 ++++++--- .../models/sale_order.py | 17 +++++++++++++++++ 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/sale_order_invoicing_finished_task/README.rst b/sale_order_invoicing_finished_task/README.rst index 81a646f23587..6d24a3f71e97 100644 --- a/sale_order_invoicing_finished_task/README.rst +++ b/sale_order_invoicing_finished_task/README.rst @@ -36,6 +36,10 @@ To use this module, you need to: .. image:: static/description/task_view_invoicefinishedtask.png + If the product is configured with an invoicing policy = Order, then the + delivered quantity is set to the ordered quantity. Otherwise, the time spent + on the task is used. + 6. Optional: if you want to use project stages to control this Go To Project -> Settings -> Stage -> You have to set true the field Invoiceable in the stages that you consider are invoiceable. Event to use stages for diff --git a/sale_order_invoicing_finished_task/__manifest__.py b/sale_order_invoicing_finished_task/__manifest__.py index a54b6a45d83b..093b3ff1a5a9 100644 --- a/sale_order_invoicing_finished_task/__manifest__.py +++ b/sale_order_invoicing_finished_task/__manifest__.py @@ -7,7 +7,7 @@ { "name": "Sale Order Invoicing Finished Task", "summary": "Control invoice order lines if his task has been finished", - "version": "10.0.1.0.1", + "version": "10.0.1.0.2", "category": "Sales", "website": "https://github.com/OCA/sale-workflow", "author": "Tecnativa, " diff --git a/sale_order_invoicing_finished_task/i18n/fr.po b/sale_order_invoicing_finished_task/i18n/fr.po index ff7a25679884..ba1e1ac5c421 100644 --- a/sale_order_invoicing_finished_task/i18n/fr.po +++ b/sale_order_invoicing_finished_task/i18n/fr.po @@ -4,13 +4,14 @@ # # Translators: # OCA Transbot , 2017 +# Quentin THEURET , 2018 msgid "" msgstr "" "Project-Id-Version: Odoo Server 10.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-11-23 01:51+0000\n" -"PO-Revision-Date: 2017-11-23 01:51+0000\n" -"Last-Translator: OCA Transbot , 2017\n" +"POT-Creation-Date: 2018-02-28 01:48+0000\n" +"PO-Revision-Date: 2018-02-28 01:48+0000\n" +"Last-Translator: Quentin THEURET , 2018\n" "Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -41,7 +42,7 @@ msgstr "" #. module: sale_order_invoicing_finished_task #: model:ir.model,name:sale_order_invoicing_finished_task.model_product_template msgid "Product Template" -msgstr "" +msgstr "Modèle de produit" #. module: sale_order_invoicing_finished_task #: model:ir.model,name:sale_order_invoicing_finished_task.model_sale_order @@ -69,19 +70,19 @@ msgid "Tasks" msgstr "" #. module: sale_order_invoicing_finished_task -#: code:addons/sale_order_invoicing_finished_task/models/project.py:70 +#: code:addons/sale_order_invoicing_finished_task/models/project.py:73 #, python-format msgid "You cannot add a task to and invoiced Sale Order Line" msgstr "" #. module: sale_order_invoicing_finished_task -#: code:addons/sale_order_invoicing_finished_task/models/project.py:55 +#: code:addons/sale_order_invoicing_finished_task/models/project.py:58 #, python-format msgid "You cannot modify the Sale Order Line of the task once it is invoiced" msgstr "" #. module: sale_order_invoicing_finished_task -#: code:addons/sale_order_invoicing_finished_task/models/project.py:45 +#: code:addons/sale_order_invoicing_finished_task/models/project.py:46 #, python-format msgid "" "You cannot modify the status if there is no Sale Order Line or if it has " diff --git a/sale_order_invoicing_finished_task/models/project.py b/sale_order_invoicing_finished_task/models/project.py index 6b59cecadf58..c88b5d0ee8e2 100644 --- a/sale_order_invoicing_finished_task/models/project.py +++ b/sale_order_invoicing_finished_task/models/project.py @@ -38,14 +38,17 @@ def _onchange_stage_id(self): @api.multi def toggle_invoiceable(self): for task in self: + sale_line = task.sale_line_id # We dont' want to modify when the related SOLine is invoiced - if (not task.sale_line_id or - task.sale_line_id.state in ('done', 'cancel') or - task.sale_line_id.invoice_status in ('invoiced',)): + if (not sale_line or + sale_line.state in ('done', 'cancel') or + sale_line.invoice_status in ('invoiced',)): raise UserError(_("You cannot modify the status if there is " "no Sale Order Line or if it has been " "invoiced.")) task.invoiceable = not task.invoiceable + if sale_line and sale_line.product_id.invoice_policy == 'order': + sale_line.qty_delivered = sale_line.product_uom_qty @api.multi def write(self, vals): diff --git a/sale_order_invoicing_finished_task/models/sale_order.py b/sale_order_invoicing_finished_task/models/sale_order.py index ebe6f7f98771..6f2b99974028 100644 --- a/sale_order_invoicing_finished_task/models/sale_order.py +++ b/sale_order_invoicing_finished_task/models/sale_order.py @@ -48,3 +48,20 @@ def _get_to_invoice_qty(self): else: line.qty_to_invoice = 0.0 super(SaleOrderLine, self - lines)._get_to_invoice_qty() + + @api.multi + def _compute_analytic(self, domain=None): + if not domain and self.ids: + domain = [ + ('so_line', 'in', self.ids), + # don't update the qty on sale order lines which are not + # with a product invoiced on ordered qty + + # invoice_finished task = True + '|', + ('so_line.product_id.invoice_policy', '!=', 'order'), + ('so_line.product_id.invoicing_finished_task', '=', False), + '|', + ('amount', '<=', 0.0), + ('project_id', '!=', False), + ] + return super(SaleOrderLine, self)._compute_analytic(domain=domain)