From 4b5188bd062165f7199b42a6c4b74530ea9d6512 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Tue, 24 May 2022 16:13:46 +0200 Subject: [PATCH] [UPD] Synchronize budget with new quotation lines By pressing button "Sync missing budget lines", a new budget section line is created for all the order lines without associated budget line. --- account_budget_forecast/__manifest__.py | 2 +- .../i18n/account_budget_forecast.pot | 15 +++++++-- account_budget_forecast/i18n/fr.po | 23 +++++++++++--- .../models/account_analytic_account.py | 1 + account_budget_forecast/models/sale_order.py | 31 +++++++++++++++++++ account_budget_forecast/views/sale_order.xml | 6 ++++ 6 files changed, 70 insertions(+), 8 deletions(-) diff --git a/account_budget_forecast/__manifest__.py b/account_budget_forecast/__manifest__.py index 0f63dfc..86fbacc 100644 --- a/account_budget_forecast/__manifest__.py +++ b/account_budget_forecast/__manifest__.py @@ -3,7 +3,7 @@ { "name": "account_budget_forecast", - "version": "13.0.1.1.0", + "version": "13.0.1.2.0", "author": "Elabore", "maintainer": "False", "website": "False", diff --git a/account_budget_forecast/i18n/account_budget_forecast.pot b/account_budget_forecast/i18n/account_budget_forecast.pot index c967eb6..6e9ce6b 100644 --- a/account_budget_forecast/i18n/account_budget_forecast.pot +++ b/account_budget_forecast/i18n/account_budget_forecast.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-05-23 21:11+0000\n" -"PO-Revision-Date: 2022-05-23 21:11+0000\n" +"POT-Creation-Date: 2022-05-24 14:53+0000\n" +"PO-Revision-Date: 2022-05-24 14:53+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -111,6 +111,7 @@ msgstr "" #: model:ir.model.fields,field_description:account_budget_forecast.field_account_analytic_account__budget_forecast_ids #: model:ir.model.fields,field_description:account_budget_forecast.field_account_analytic_line__budget_forecast_id #: model:ir.model.fields,field_description:account_budget_forecast.field_account_move_line__budget_forecast_id +#: model:ir.model.fields,field_description:account_budget_forecast.field_sale_order_line__budget_forecast_id msgid "Budget Forecast" msgstr "" @@ -596,6 +597,11 @@ msgstr "" msgid "Sales Order" msgstr "" +#. module: account_budget_forecast +#: model:ir.model,name:account_budget_forecast.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + #. module: account_budget_forecast #: model:ir.model.fields.selection,name:account_budget_forecast.selection__budget_forecast__display_type__line_section #: model:ir.model.fields.selection,name:account_budget_forecast.selection__budget_forecast_model_line__display_type__line_section @@ -632,6 +638,11 @@ msgstr "" msgid "Summary" msgstr "" +#. module: account_budget_forecast +#: model_terms:ir.ui.view,arch_db:account_budget_forecast.view_order_form +msgid "Sync missing budget lines" +msgstr "" + #. module: account_budget_forecast #: model_terms:ir.ui.view,arch_db:account_budget_forecast.view_analytic_budget_forecast msgid "Total" diff --git a/account_budget_forecast/i18n/fr.po b/account_budget_forecast/i18n/fr.po index 85c521e..fb55c31 100644 --- a/account_budget_forecast/i18n/fr.po +++ b/account_budget_forecast/i18n/fr.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-05-23 21:09+0000\n" -"PO-Revision-Date: 2022-05-23 21:09+0000\n" +"POT-Creation-Date: 2022-05-24 14:52+0000\n" +"PO-Revision-Date: 2022-05-24 14:52+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -32,7 +32,7 @@ msgstr "Réel" #. module: account_budget_forecast #: model:ir.model.fields,field_description:account_budget_forecast.field_budget_forecast__actual_qty msgid "Actual Quantity" -msgstr "Quantité réelle" +msgstr "Quantité actuelle" #. module: account_budget_forecast #: model_terms:ir.ui.view,arch_db:account_budget_forecast.budget_forecast_category_miscellaneous @@ -113,6 +113,7 @@ msgstr "Coefficients de chiffrage" #: model:ir.model.fields,field_description:account_budget_forecast.field_account_analytic_account__budget_forecast_ids #: model:ir.model.fields,field_description:account_budget_forecast.field_account_analytic_line__budget_forecast_id #: model:ir.model.fields,field_description:account_budget_forecast.field_account_move_line__budget_forecast_id +#: model:ir.model.fields,field_description:account_budget_forecast.field_sale_order_line__budget_forecast_id msgid "Budget Forecast" msgstr "Chiffrage" @@ -180,7 +181,7 @@ msgstr "Modèles de coefficient" #. module: account_budget_forecast #: model:ir.ui.menu,name:account_budget_forecast.menu_budget_forecast msgid "Budget forecast" -msgstr "Budget prévisionnel" +msgstr "Lignes de chiffrage" #. module: account_budget_forecast #: model:ir.model.fields,field_description:account_budget_forecast.field_product_product__budget_level @@ -598,6 +599,11 @@ msgstr "Réinitialiser le budget" msgid "Sales Order" msgstr "Bon de commande" +#. module: account_budget_forecast +#: model:ir.model,name:account_budget_forecast.model_sale_order_line +msgid "Sales Order Line" +msgstr "Ligne de bons de commande" + #. module: account_budget_forecast #: model:ir.model.fields.selection,name:account_budget_forecast.selection__budget_forecast__display_type__line_section #: model:ir.model.fields.selection,name:account_budget_forecast.selection__budget_forecast_model_line__display_type__line_section @@ -634,6 +640,11 @@ msgstr "Sous-traitants" msgid "Summary" msgstr "Résumé" +#. module: account_budget_forecast +#: model_terms:ir.ui.view,arch_db:account_budget_forecast.view_order_form +msgid "Sync missing budget lines" +msgstr "Synchroniser les lignes budgétaires manquantes" + #. module: account_budget_forecast #: model_terms:ir.ui.view,arch_db:account_budget_forecast.view_analytic_budget_forecast msgid "Total" @@ -680,7 +691,9 @@ msgstr "" #, python-format msgid "" "You must add an analytic account to build/access the budget forecast screen." -msgstr "Vous devez ajouter un compte analytic pour construire et accéder au budget prévisionnel" +msgstr "" +"Vous devez ajouter un compte analytic pour construire et accéder au budget " +"prévisionnel" #. module: account_budget_forecast #: model:ir.model,name:account_budget_forecast.model_budget_coefficient_model diff --git a/account_budget_forecast/models/account_analytic_account.py b/account_budget_forecast/models/account_analytic_account.py index 06a0854..97884ca 100644 --- a/account_budget_forecast/models/account_analytic_account.py +++ b/account_budget_forecast/models/account_analytic_account.py @@ -263,6 +263,7 @@ class AccountAnalyticAccount(models.Model): "name": section.product_id.name, "product_uom_qty": 1.0, "price_unit": section.plan_amount_with_coeff, + "budget_forecast_id": section.id, } self.env["sale.order.line"].create(values) quotation.analytic_account_id = self.id diff --git a/account_budget_forecast/models/sale_order.py b/account_budget_forecast/models/sale_order.py index 5974943..883f1b2 100644 --- a/account_budget_forecast/models/sale_order.py +++ b/account_budget_forecast/models/sale_order.py @@ -16,6 +16,31 @@ class SaleOrder(models.Model): raise Warning(_("Please set the analytic account")) return self.analytic_account_id.action_budget_forecast() + def sync_missing_budget_lines(self): + for record in self: + for line in self.order_line: + if not line.budget_forecast_id: + values = { + "analytic_id": record.analytic_account_id.id, + "product_id": line.product_id.id, + "description": line.name, + "is_summary": True, + "display_type": "line_section", + "sequence": 999, + } + budget_line = self.env["budget.forecast"].create(values) + misc_budget_line = self.env["budget.forecast"].search( + [ + ("summary_id", "=", budget_line.id), + ("budget_category", "=", "miscellaneous"), + ] + ) + misc_budget_line.plan_qty = 1 + misc_budget_line.plan_price = line.price_unit / ( + 1 + record.analytic_account_id.global_coeff + ) + line.budget_forecast_id = budget_line.id + @api.returns("self", lambda value: value.id) def copy(self, default=None): record = super(SaleOrder, self).copy(default=default) @@ -28,3 +53,9 @@ class SaleOrder(models.Model): default=dict(name=name) ) return record + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + budget_forecast_id = fields.Many2one("budget.forecast") diff --git a/account_budget_forecast/views/sale_order.xml b/account_budget_forecast/views/sale_order.xml index 7a57462..e912b08 100644 --- a/account_budget_forecast/views/sale_order.xml +++ b/account_budget_forecast/views/sale_order.xml @@ -6,11 +6,17 @@ sale.order +
+
+ + +