diff --git a/models/sale_order.py b/models/sale_order.py index 0f913e7a4dff15cdc6cc5ecc57aded7e1b4d3e68..fae82d658174cb2b9d29f8b9d633c4f0ce822822 100644 --- a/models/sale_order.py +++ b/models/sale_order.py @@ -2,7 +2,7 @@ # © 2018 Le Filament (http://www.le-filament.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import fields, models +from odoo import api, fields, models class SaleOrder(models.Model): @@ -12,6 +12,19 @@ class SaleOrder(models.Model): confirmation_date = fields.Datetime(readonly=False) estimated_date_invoice = fields.Date("Date de facturation prévisionnelle") + # ------------------------------------------------------ + # Onchange + # ------------------------------------------------------ + @api.onchange("estimated_date_invoice") + def _onchange_estimated_date_invoice(self): + """Update order lines with estimated invoice date from sale order""" + if self.estimated_date_invoice: + for line in self.order_line: + line.estimated_date_invoice = self.estimated_date_invoice + + # ------------------------------------------------------ + # Override parent + # ------------------------------------------------------ def _prepare_invoice(self): values = super(SaleOrder, self)._prepare_invoice() values.update( diff --git a/models/sale_order_line.py b/models/sale_order_line.py index ce85965b38724a7567c8806c0b38aa633fa4b035..a611b87ca2ad8c8cbe1b22cf14b569974d5e3db1 100644 --- a/models/sale_order_line.py +++ b/models/sale_order_line.py @@ -11,7 +11,11 @@ class SaleOrderLine(models.Model): insurances = fields.Many2many( "ecozimut.insurance", ondelete="cascade", string="Assurances", index=True ) + estimated_date_invoice = fields.Date("Date de facturation prévisionnelle") + # ------------------------------------------------------ + # Onchange + # ------------------------------------------------------ @api.onchange("product_id") def product_id_change(self): res = super(SaleOrderLine, self).product_id_change() @@ -19,3 +23,13 @@ class SaleOrderLine(models.Model): if not line.insurances: line.insurances = line.product_id.insurances return res + + # ------------------------------------------------------ + # Override parent + # ------------------------------------------------------ + def _timesheet_create_task_prepare_values(self, project): + values = super()._timesheet_create_task_prepare_values() + values['date_end'] = self.estimated_date_invoice + values['date_deadline'] = self.estimated_date_invoice + return values + diff --git a/views/sale_order.xml b/views/sale_order.xml index f545627020a192d73f0d9ba9a834b06209b63151..72673510758636fca31a53d79324315b20224575 100644 --- a/views/sale_order.xml +++ b/views/sale_order.xml @@ -1,6 +1,6 @@ <odoo> <data> - + <!-- Form view --> <record id="view_sales_order_auto_done_setting" model="ir.ui.view"> <field name="name">sale.order.form</field> <field name="model">sale.order</field> @@ -12,6 +12,7 @@ </field> </record> + <!-- Form view --> <record id="ecozimut_businessDeveloper_view" model="ir.ui.view"> <field name="name">ecozimut.businessDeveloper.view</field> <field name="model">sale.order</field> @@ -31,6 +32,11 @@ widget="many2many_tags" optional="show" /> + <field + name="estimated_date_invoice" + string="Prévi factu" + optional="show" + /> </xpath> <field name="payment_term_id" position="after"> <field name="estimated_date_invoice" />