diff --git a/__manifest__.py b/__manifest__.py index ac8d7ece03c84764fb2781d2d2085ea383603084..8c2fa43f5f335e5ec3035d5bf5e86f1b33279c92 100755 --- a/__manifest__.py +++ b/__manifest__.py @@ -11,6 +11,7 @@ 'data': [ "security/ir.model.access.csv", # datas + 'data/data.xml', # wizard 'wizard/acc_sale_price_wizard_views.xml', 'wizard/acc_account_wizard_views.xml', diff --git a/data/data.xml b/data/data.xml new file mode 100644 index 0000000000000000000000000000000000000000..f8316324135b6157a99cb89cf1d95dab78fd182b --- /dev/null +++ b/data/data.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <data noupdate="1"> + <!-- + Precisions + --> + <record forcecreate="True" id="decimal_sale_price" model="decimal.precision"> + <field name="name">Sale Price</field> + <field name="digits">3</field> + </record> + + </data> +</odoo> diff --git a/models/acc_account.py b/models/acc_account.py index 9b6cc24c83e4911836b11b46e407cb6f4ad41e97..1512e8a6cd5e47d6ea439f3f132c67480d1b90bb 100644 --- a/models/acc_account.py +++ b/models/acc_account.py @@ -104,9 +104,13 @@ class AccAccount(models.Model): readonly=True, compute='_compute_amount') # inverse='_inverse_amount_total') - price_kwh = fields.Float("Prix de l'électricité au kWh") + price_kwh = fields.Float( + "Prix de l'électricité au kWh", digits="Sale Price") power_cons = fields.Float("Consommation locale (index Enedis)") url = fields.Char("URL", compute="_compute_url", store=True) + tax_tcfe = fields.Float( + "Taxes CPSE/TCF (en €/kWh)", + digits="Sale Price") @api.model_create_multi def create(self, vals_list): @@ -134,6 +138,7 @@ class AccAccount(models.Model): for move in self: total_tax = 0.0 total = 0.0 + tax_tcfe = 0.0 for line in move.line_ids: total += line.price_total @@ -141,9 +146,12 @@ class AccAccount(models.Model): if move.is_tva and move.tax_id: total_tax = ((total * move.tax_id.amount) / 100) + if move.tax_tcfe > 0: + tax_tcfe = ((total * move.tax_tcfe) / 100) + move.amount_untaxed = total move.amount_tax = total_tax - move.amount_total = total + total_tax + move.amount_total = total + total_tax + tax_tcfe def _compute_url(self): for account in self: @@ -174,7 +182,9 @@ class AccAccountLine(models.Model): quantity = fields.Float( string="Quantité", default=1.0) - price_unit = fields.Float(string="Prix unitaire") + price_unit = fields.Float( + string="Prix unitaire", + digits="Sale Price") currency_id = fields.Many2one( "res.currency", string="Devise", diff --git a/models/acc_counter.py b/models/acc_counter.py index 6742864d67549b9a76d7730b1b72d1708c2918af..023f0cd3f17d14bc327abd07f831f23e99ed4327 100644 --- a/models/acc_counter.py +++ b/models/acc_counter.py @@ -33,6 +33,9 @@ class AccCounter(models.Model): acc_account_surplus_count = fields.Integer( compute="_compute_acc_account_count", string="Nombre de factures surplus producteurs" ) + is_account_auto_activate = fields.Boolean("Facturation de l’autoconsommation automatisée") + is_account_surplus_activate = fields.Boolean("Facturation du surplus automatisée") + # ------------------------------------------------------ # SQL Constraints # ------------------------------------------------------ diff --git a/models/acc_operation.py b/models/acc_operation.py index 1dad26ad4a97272a74664aadd7f58807dea97b4c..a26bf50a53a0a69970383d87a53b642e7e7ead94 100644 --- a/models/acc_operation.py +++ b/models/acc_operation.py @@ -17,13 +17,22 @@ class AccOperation(models.Model): acc_sale_price_ids = fields.One2many( "acc.sale.price", "acc_operation_id") acc_account_ids = fields.One2many( - "acc.account", "acc_operation_id" + "acc.account", "acc_operation_id", + domain=[("is_account_buyer", "=", False)], + string="Factures" + ) + acc_account_surplus_ids = fields.One2many( + "acc.account", "acc_operation_id", + domain=[("is_account_buyer", "=", True)], + string="Factures Surplus" ) acc_account_line_ids = fields.One2many( "acc.account.line", "acc_operation_id" ) acc_account_count = fields.Integer( string="Nombre de factures", compute="_compute_acc_account_count") + tax_tcfe = fields.Float("Taxes CPSE/TCF (en €/kWh)", digits="Sale Price") + # ------------------------------------------------------ # SQL Constraints # ------------------------------------------------------ @@ -87,7 +96,6 @@ class AccOperation(models.Model): return power_tab_by_prod def create_account(self, date_month, account_periodicity): - result = dict() account_list = [] date_end = date_utils.end_of(date_month, 'month') @@ -109,45 +117,47 @@ class AccOperation(models.Model): prod_tot = power_tab_by_prod[0]['power'] - power_tab_by_prod[1]['power'] for acc_injection_id in self.acc_injection_ids: - power_tab_by_prod = self.get_power_by_prod(acc_injection_id, date_start, date_end) - - power_autoprod_percent = ((power_tab_by_prod[0]['power'] - power_tab_by_prod[1]['power']) * 100) / prod_tot - power_tab_by_cons = self.get_power_by_cons(date_start, date_end) - for power_cons in power_tab_by_cons: - - power_month = (power_cons['power'] / 1000 / 2) * (power_autoprod_percent / 100) - - price_kwh = self.env['acc.sale.price'].search([ - ('acc_operation_id', '=', self.id), - ('acc_injection_id', '=', acc_injection_id.id), - ('acc_delivery_id', '=', power_cons['acc_counter_id'][0]), - ('start_date', '<=', date_month), - ('end_date', '>=', date_month) - ]).price - - Account = self.env['acc.account'] - AccountLine = self.env['acc.account.line'] - - acc_account = Account.create({ - 'acc_operation_id': self.id, - 'acc_injection_id': acc_injection_id.id, - 'acc_delivery_id': power_cons['acc_counter_id'][0], - 'power_cons': power_month, - 'start_date': date_start, - 'end_date': date_end, - 'price_kwh': price_kwh - }) - - # Création de la ligne du mois - acc_account_line = AccountLine.create({ - 'quantity': power_month, - 'price_unit': price_kwh, - 'acc_account_id': acc_account.id, - 'start_date': date_start, - 'end_date': date_end, - 'description': 'Facture pour le mois de ' + date_month.strftime("%B") - }) - account_list.append(acc_account) + if acc_injection_id.is_account_auto_activate: + power_tab_by_prod = self.get_power_by_prod(acc_injection_id, date_start, date_end) + + power_autoprod_percent = ((power_tab_by_prod[0]['power'] - power_tab_by_prod[1]['power']) * 100) / prod_tot + power_tab_by_cons = self.get_power_by_cons(date_start, date_end) + for power_cons in power_tab_by_cons: + + power_month = (power_cons['power'] / 1000 / 2) * (power_autoprod_percent / 100) + + price_kwh = self.env['acc.sale.price'].search([ + ('acc_operation_id', '=', self.id), + ('acc_injection_id', '=', acc_injection_id.id), + ('acc_delivery_id', '=', power_cons['acc_counter_id'][0]), + ('start_date', '<=', date_month), + ('end_date', '>=', date_month) + ]).price + + Account = self.env['acc.account'] + AccountLine = self.env['acc.account.line'] + + acc_account = Account.create({ + 'acc_operation_id': self.id, + 'acc_injection_id': acc_injection_id.id, + 'acc_delivery_id': power_cons['acc_counter_id'][0], + 'power_cons': power_month, + 'start_date': date_start, + 'end_date': date_end, + 'price_kwh': price_kwh, + 'tax_tcfe': self.tax_tcfe, + }) + + # Création de la ligne du mois + acc_account_line = AccountLine.create({ + 'quantity': power_month, + 'price_unit': price_kwh, + 'acc_account_id': acc_account.id, + 'start_date': date_start, + 'end_date': date_end, + 'description': 'Facture pour le mois de ' + date_month.strftime("%B") + }) + account_list.append(acc_account) action = self.env["ir.actions.actions"]._for_xml_id( "acc_account.action_acc_account" @@ -158,7 +168,6 @@ class AccOperation(models.Model): return action def create_account_surplus(self, date_month, account_periodicity): - result = dict() account_list = [] date_end = date_utils.end_of(date_month, 'month') @@ -174,38 +183,40 @@ class AccOperation(models.Model): ['acc_counter_id'], orderby='comp_data_type', lazy=False) for power_tab_prod in power_tab_by_prod: + injection_id = self.env['acc.counter'].browse(power_tab_prod['acc_counter_id'][0]) + if injection_id.is_account_surplus_activate: + price_kwh = self.env['acc.sale.price.buyer'].search([ + ('acc_injection_id', '=', injection_id.id), + ('acc_buyer_id', '=', injection_id.buyer_id.id), + ('start_date', '<=', date_month), + ('end_date', '>=', date_month) + ]).price + + Account = self.env['acc.account'] + AccountLine = self.env['acc.account.line'] + + acc_account = Account.create({ + 'acc_operation_id': self.id, + 'buyer_id': self.buyer_id.id, + 'acc_injection_id': injection_id.id, + 'power_cons': power_tab_prod['power'], + 'start_date': date_start, + 'end_date': date_end, + 'price_kwh': price_kwh, + 'is_account_buyer': True, + 'tax_tcfe': self.tax_tcfe, + }) - price_kwh = self.env['acc.sale.price.buyer'].search([ - ('acc_operation_id', '=', self.id), - ('acc_buyer_id', '=', self.buyer_id.id), - ('start_date', '<=', date_month), - ('end_date', '>=', date_month) - ]).price - - Account = self.env['acc.account'] - AccountLine = self.env['acc.account.line'] - - acc_account = Account.create({ - 'acc_operation_id': self.id, - 'buyer_id': self.buyer_id.id, - 'acc_injection_id': power_tab_prod['acc_counter_id'][0], - 'power_cons': power_tab_prod['power'], - 'start_date': date_start, - 'end_date': date_end, - 'price_kwh': price_kwh, - 'is_account_buyer': True - }) - - # Création de la ligne du mois - acc_account_line = AccountLine.create({ - 'quantity': power_tab_prod['power'], - 'price_unit': price_kwh, - 'acc_account_id': acc_account.id, - 'start_date': date_start, - 'end_date': date_end, - 'description': 'Facture pour le mois de ' + date_month.strftime("%B") - }) - account_list.append(acc_account) + # Création de la ligne du mois + acc_account_line = AccountLine.create({ + 'quantity': power_tab_prod['power'], + 'price_unit': price_kwh, + 'acc_account_id': acc_account.id, + 'start_date': date_start, + 'end_date': date_end, + 'description': 'Facture pour le mois de ' + date_month.strftime("%B") + }) + account_list.append(acc_account) action = self.env["ir.actions.actions"]._for_xml_id( "acc_account.action_acc_account" diff --git a/models/acc_sale_price.py b/models/acc_sale_price.py index 213d0cdec19a6a32bc1e32686e997435cc8358e9..9a25d28b5bb256b7063f3ed6ad2325663d33e7c3 100644 --- a/models/acc_sale_price.py +++ b/models/acc_sale_price.py @@ -34,7 +34,7 @@ class AccSalePrice(models.Model): end_date = fields.Date("Fin de la période") currency_id = fields.Many2one( 'res.currency', 'Devise', default=_get_default_currency_id) - price = fields.Float("Tarif") + price = fields.Float("Tarif", digits='Sale Price') class AccSalePriceBuyer(models.Model): @@ -47,10 +47,12 @@ class AccSalePriceBuyer(models.Model): # ------------------------------------------------------ # Fields declaration # ------------------------------------------------------ - acc_operation_id = fields.Many2one( - "acc.operation", - "Opération", - ondelete="cascade") + acc_injection_id = fields.Many2one( + 'acc.counter', + domain=[('is_injection', '=', True)], + string="Point d'injection", + ondelete="cascade" + ) acc_buyer_id = fields.Many2one( 'res.partner', domain=[('is_buyer_surplus', '=', True)], @@ -61,4 +63,4 @@ class AccSalePriceBuyer(models.Model): end_date = fields.Date("Fin de la période") currency_id = fields.Many2one( 'res.currency', 'Devise', default=_get_default_currency_id) - price = fields.Float("Tarif") + price = fields.Float("Tarif", digits='Sale Price') diff --git a/views/acc_account_views.xml b/views/acc_account_views.xml index fc5ccb39fdbf598203bf9c46d578b997fb0e189a..be4bc51dd76fde71bfc4bed10623626431ac9128 100644 --- a/views/acc_account_views.xml +++ b/views/acc_account_views.xml @@ -192,7 +192,8 @@ <field name="start_date" /> <field name="end_date" /> <field name="power_cons"/> - <field name="price_kwh"/> + <field name="price_kwh" options="{'field_digits': True}"/> + <field name="tax_tcfe" options="{'field_digits': True}"/> </group> </group> <group> @@ -213,7 +214,7 @@ options="{'no_create': True}" invisible="1"/> <field name="description"/> <field name="quantity"/> - <field name="price_unit" string="Price"/> + <field name="price_unit" string="Price" options="{'field_digits': True}"/> <field name="is_tva" invisible="1"/> <field name="tax_id" options="{'no_create': True}" diff --git a/views/acc_counter_views.xml b/views/acc_counter_views.xml index 4dd38df12cd0169453bf8d0ce4fe602442d789a2..364599154afe4c894dd6d02d57b8a1bb7d47076f 100644 --- a/views/acc_counter_views.xml +++ b/views/acc_counter_views.xml @@ -15,12 +15,13 @@ icon="fa-money" name="action_view_acc_injection_accounts" context="{'default_acc_injection_id': active_id}" + attrs="{'invisible': [('is_injection', '!=', True)]}" > <div class="o_form_field o_stat_info"> <span class="o_stat_value"> <field name="acc_account_surplus_count" /> </span> - <span class="o_stat_text">Factures Surplus producteurs</span> + <span class="o_stat_text">Factures Surplus</span> </div> </button> <button @@ -29,6 +30,7 @@ icon="fa-money" name="action_view_acc_injection_accounts" context="{'default_acc_injection_id': active_id}" + attrs="{'invisible': [('is_injection', '!=', True)]}" > <div class="o_form_field o_stat_info"> <span class="o_stat_value"> @@ -43,6 +45,7 @@ icon="fa-money" name="action_view_acc_delivery_accounts" context="{'default_acc_delivery_id': active_id}" + attrs="{'invisible': [('is_delivery', '!=', True)]}" > <div class="o_form_field o_stat_info"> <span class="o_stat_value"> @@ -56,6 +59,14 @@ <group name="infos" position="after"> <notebook> <page string="Facturation" name="account"> + <group> + <group> + <field name="is_account_auto_activate" widget="boolean_toggle"/> + </group> + <group> + <field name="is_account_surplus_activate" widget="boolean_toggle"/> + </group> + </group> <field name="acc_account_delivery_ids" widget="one2many"> diff --git a/views/acc_operation_views.xml b/views/acc_operation_views.xml index 769c871376f55585aa1adae2a99de1ee64cd9468..42cd9455d9a10a9acba8cbe8bea3258620f471a4 100644 --- a/views/acc_operation_views.xml +++ b/views/acc_operation_views.xml @@ -24,7 +24,6 @@ type="action" name="%(acc_account.acc_account_surplus_wizard_action)d" class="btn-primary" - attrs="{'invisible': [('buyer_id', '=', False)]}" /> </header> <div class="oe_title" position="before"> @@ -67,17 +66,46 @@ </page> <page string="Facturation" name="account" attrs="{'invisible': [('is_account_active', '=', False)]}"> + <group> + <field name="tax_tcfe" options="{'field_digits': True}"/> + </group> <field name="acc_account_ids" widget="one2many" - context="{'default_acc_operation_id': active_id}"> - <tree string="Facturation" editable="bottom"> + options="{'no_create': True}" + context="{'default_acc_operation_id': active_id}" + readonly="1"> + <tree string="Facturation"> <field name="acc_operation_id" invisible="1"/> <field name="name"/> <field name="date"/> <field name="acc_injection_id"/> <field name="acc_delivery_id"/> - <field name="amount_total"/> + <field name="start_date"/> + <field name="end_date"/> + <field name="amount_total" sum="Total" /> + <field name="is_account_buyer" invisible="1"/> + </tree> + </field> + </page> + <page string="Facturation Surplus" name="account" + attrs="{'invisible': [('is_account_active', '=', False)]}"> + <field + name="acc_account_surplus_ids" + widget="one2many" + options="{'no_create': True}" + readonly="1" + context="{'default_acc_operation_id': active_id, 'default_is_account_active': True}"> + <tree string="Facturation Surplus"> + <field name="acc_operation_id" invisible="1"/> + <field name="is_account_buyer" invisible="1"/> + <field name="name"/> + <field name="date"/> + <field name="acc_injection_id"/> + <field name="buyer_id"/> + <field name="start_date"/> + <field name="end_date"/> + <field name="amount_total" sum="Total"/> </tree> </field> </page> diff --git a/views/acc_sale_price_views.xml b/views/acc_sale_price_views.xml index a460d6e2966bb0b134ad86d31d1082d0b7e96be5..99e803261c7dbee9c263a8908311f17fd6a35140 100644 --- a/views/acc_sale_price_views.xml +++ b/views/acc_sale_price_views.xml @@ -17,7 +17,9 @@ <group> <field name="start_date"/> <field name="end_date"/> - <field name="price" widget='monetary'/> + <field name="price" + widget='monetary' + options="{'field_digits': True}"/> <field name="currency_id"/> </group> </group> @@ -37,7 +39,9 @@ <field name="start_date"/> <field name="end_date"/> <field name="currency_id" invisible="1"/> - <field name="price" widget='monetary'/> + <field name="price" + widget="monetary" + options="{'field_digits': True}"/> </tree> </field> </record> @@ -62,13 +66,15 @@ <sheet> <group> <group> - <field name="acc_operation_id"/> + <field name="acc_injection_id"/> <field name="acc_buyer_id"/> </group> <group> <field name="start_date"/> <field name="end_date"/> - <field name="price" widget='monetary'/> + <field name="price" + widget="monetary" + options="{'field_digits': True}"/> <field name="currency_id"/> </group> </group> @@ -82,12 +88,14 @@ <field name="model">acc.sale.price.buyer</field> <field name="arch" type="xml"> <tree string="Prix de vente Acheteur"> - <field name="acc_operation_id"/> + <field name="acc_injection_id"/> <field name="acc_buyer_id"/> <field name="start_date"/> <field name="end_date"/> <field name="currency_id" invisible="1"/> - <field name="price" widget='monetary'/> + <field name="price" + widget="monetary" + options="{'field_digits': True}"/> </tree> </field> </record>