From 63fe133048499eafa364ea2b2c97c1a8516d5119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20-=20Le=20Filament?= <remi@le-filament.com> Date: Tue, 5 Jul 2022 11:58:34 +0200 Subject: [PATCH] [ADD] different accounts on forfaits --- __manifest__.py | 3 ++- models/__init__.py | 2 ++ models/product_template.py | 18 +++++++++++++++++ models/sale_order_line.py | 34 ++++++++++++++++++++++++++++++++ models/sale_project.py | 4 ++-- views/product_template_view.xml | 20 +++++++++++++++++++ views/sale_intervention_view.xml | 2 +- 7 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 models/product_template.py create mode 100644 models/sale_order_line.py create mode 100644 views/product_template_view.xml diff --git a/__manifest__.py b/__manifest__.py index 05fed29..ec81bae 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -3,11 +3,12 @@ "summary": "Ajout des taxes sur les devis", "author": "Le Filament", "website": "https://le-filament.com", - "version": "14.0.1.0.0", + "version": "14.0.2.0.0", "license": "AGPL-3", "depends": ["ap_sale_project", "product_category_tax"], "data": [ # views + "views/product_template_view.xml", "views/sale_intervention_view.xml", ], "installable": True, diff --git a/models/__init__.py b/models/__init__.py index 7e691b3..9e19720 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -1,6 +1,8 @@ # Copyright 2021-2022 Le Filament (https://le-filament.com) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) +from . import product_template from . import sale_intervention from . import sale_project from . import sale_order +from . import sale_order_line diff --git a/models/product_template.py b/models/product_template.py new file mode 100644 index 0000000..b719b6f --- /dev/null +++ b/models/product_template.py @@ -0,0 +1,18 @@ +# Copyright 2022 Le Filament (https://le-filament.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import fields, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + # Specific behavior for AP32, added a second income account for forfaits + property_account_service_income_id = fields.Many2one( + "account.account", + company_dependent=True, + string="Compte de revenus (Service)", + domain=[("deprecated", "=", False)], + help="Ce champ permet de définir un compte différent pour les activités" + " de service sur un forfait.", + ) diff --git a/models/sale_order_line.py b/models/sale_order_line.py new file mode 100644 index 0000000..f84f64c --- /dev/null +++ b/models/sale_order_line.py @@ -0,0 +1,34 @@ +# Copyright 2022 Le Filament (https://le-filament.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import models + + +class SaleOrderLine(models.Model): + _inherit = "sale.order.line" + + # ------------------------------------------------------ + # Business method + # ------------------------------------------------------ + def _prepare_invoice_line(self, **optional_values): + # Method to update account on invoice line in case service account + # is different from base account (AP32 has 2 different accounts for the same product) + res = super(SaleOrderLine, self)._prepare_invoice_line(**optional_values) + if res.get("product_id"): + product_id = self.env["product.product"].browse(res.get("product_id")) + product_tmpl_id = product_id.product_tmpl_id + if product_tmpl_id.property_account_service_income_id and ( + product_tmpl_id.property_account_income_id.id + != product_tmpl_id.property_account_service_income_id.id + ): + furniture_categ_id = self.env.ref( + "ap_sale_project.product_category_plantation_supply" + ) + vat_furniture_categ = ( + self.env["product.category"].browse(furniture_categ_id.id).taxes_id + ) + if res.get("tax_ids") == [(6, 0, vat_furniture_categ.mapped("id"))]: + res[ + "account_id" + ] = product_tmpl_id.property_account_service_income_id.id + return res diff --git a/models/sale_project.py b/models/sale_project.py index abaa606..ef56d8a 100644 --- a/models/sale_project.py +++ b/models/sale_project.py @@ -111,7 +111,7 @@ class SaleProject(models.Model): **data_sol_section, **{ "price_unit": plant_price, - "name": sol_name + " - Plants garantis 3 ans", + "name": "Plants garantis 3 ans", "tax_id": [(6, 0, vat_plant_categ.ids)], }, } @@ -121,7 +121,7 @@ class SaleProject(models.Model): **data_sol_section, **{ "price_unit": price_unit - plant_price, - "name": sol_name + " - Paillage, protections, " + "name": "Paillage, protections, " "ingénierie, livraison et suivi", "tax_id": [(6, 0, vat_furniture_categ.ids)], }, diff --git a/views/product_template_view.xml b/views/product_template_view.xml new file mode 100644 index 0000000..734575c --- /dev/null +++ b/views/product_template_view.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- Copyright 2022 Le Filament + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). --> +<odoo> + <data> + <record id="product_template_form_view_2nd_account" model="ir.ui.view"> + <field name="name">product.template.form</field> + <field name="model">product.template</field> + <field name="inherit_id" ref="account.product_template_form_view" /> + <field name="arch" type="xml"> + <field name="property_account_income_id" position="after"> + <field + name="property_account_service_income_id" + attrs="{'invisible': [('categ_id', '!=', %(ap_sale_project.product_category_forfait)d)]}" + /> + </field> + </field> + </record> + </data> +</odoo> diff --git a/views/sale_intervention_view.xml b/views/sale_intervention_view.xml index d35c6d4..3e5e370 100644 --- a/views/sale_intervention_view.xml +++ b/views/sale_intervention_view.xml @@ -11,7 +11,7 @@ <field name="collarette_qty" position="after"> <field name="collarette_calc" - attrs="{'invisible': [('is_collarette', '!=', True), ('intervention_uom_name', '!=', 'm')]}" + attrs="{'invisible': [('is_collarette', '!=', True)]}" /> </field> </field> -- GitLab