diff --git a/migrations/16.0.4.0.2/post-migration.py b/migrations/16.0.4.0.2/post-migration.py index d29c360b6acbdec5a9e3a6a3d3e6f0942229ffad..1a54342747399bb164fedc7dce86a3b851ae38b9 100644 --- a/migrations/16.0.4.0.2/post-migration.py +++ b/migrations/16.0.4.0.2/post-migration.py @@ -5,7 +5,6 @@ from openupgradelib import openupgrade @openupgrade.migrate() def migrate(env, version): - moves = env["account.move"].search([("move_type", "=", "out_refund")]) for move in moves: move._compute_amount_oacc() diff --git a/models/account_move.py b/models/account_move.py index 96656a7934dd7cee149cad5816c1b1330cc7f532..f61d9926f822c50b0ea0b5a8a3aad60da081fc0a 100644 --- a/models/account_move.py +++ b/models/account_move.py @@ -57,7 +57,8 @@ class AccountMove(models.Model): ) power_cons_display = fields.Float( - "Electricité locale (kwh)", digits="Unité de Mesure", + "Electricité locale (kwh)", + digits="Unité de Mesure", store=True, readonly=True, compute="_compute_power_cons_display", @@ -163,7 +164,7 @@ class AccountMove(models.Model): Calcul de la quantité facturée a afficher ( négatif si facture extournée) """ for move in self: - if move.move_type == 'out_refund': + if move.move_type == "out_refund": move.power_cons_display = move.power_cons * -1 else: move.power_cons_display = move.power_cons @@ -173,7 +174,7 @@ class AccountMove(models.Model): "line_ids.price_total", "line_ids.price_unit", "line_ids.quantity", - "move_type" + "move_type", ) def _compute_amount_oacc(self): """ @@ -203,7 +204,7 @@ class AccountMove(models.Model): else: tot_divers += line.price_subtotal - if move.move_type == 'out_refund': + if move.move_type == "out_refund": move.amount_accise_tot = tot_accise * -1 move.amount_elec_tot = tot_elec * -1 move.amount_divers_tot = tot_divers * -1 @@ -595,11 +596,13 @@ class AccountMove(models.Model): elif self.acc_operation_id.subscription_type == "kw": quantity = move.power_cons - subscription_move_line = move._process_create_subscription_move_line( - quantity, - delivery_id, - counter_start_date, - counter_end_date, + subscription_move_line = ( + move._process_create_subscription_move_line( + quantity, + delivery_id, + counter_start_date, + counter_end_date, + ) ) if subscription_move_line: move_lines_to_create.append(subscription_move_line) diff --git a/models/res_partner.py b/models/res_partner.py index a1fad2ff64742c0fc030a8f5640c9420755e81b1..f0b05c0bde368575fe730c556ee58c1a73c0a402 100644 --- a/models/res_partner.py +++ b/models/res_partner.py @@ -54,37 +54,62 @@ class ResPartner(models.Model): # ------------------------------------------------------ # Business methods # ------------------------------------------------------ + def get_linked_company_data(self): + """ + Retourne un dictionnaire contenant les données de creation de la société liées + """ + company_data = super().get_linked_company_data() + # mise en page + company_data["external_report_layout_id"] = self.env.ref( + "oacc_account.external_layout_oacc" + ).id + # escompte + company_data["early_pay_discount_computation"] = "excluded" + # devise + company_data["currency_id"] = ( + self.env["res.currency"].search([("name", "=", "EUR")]).id + ) + # methode d arrondi + company_data["tax_calculation_rounding_method"] = "round_globally" + # pays fiscal (normalement renseigné via le pays) + if not company_data.get("account_fiscal_country_id"): + company_data["account_fiscal_country_id"] = self.env.ref("base.fr").id + + company_data["account_purchase_tax_id"] = ( + self.env["account.tax.template"] + .search( + [ + ("name", "=", "TVA 20%"), + ("type_tax_use", "=", "purchase"), + ("tax_scope", "=", "service"), + ] + ) + .id + ) + company_data["account_sale_tax_id"] = ( + self.env["account.tax.template"] + .search( + [ + ("name", "=", "TVA 20%"), + ("type_tax_use", "=", "sale"), + ("tax_scope", "=", "service"), + ] + ) + .id + ) + company_data["invoice_terms_tax"] = True + company_data["use_invoice_terms_tax"] = True + company_data["chart_template_id"] = ( + self.env["account.chart.template"] + .search([("country_id", "=", self.country_code)]) + .id + ) + + return company_data # ------------------------------------------------------ # CRUD methods (ORM overrides) # ------------------------------------------------------ - @api.model_create_multi - def create(self, vals_list): - for vals in vals_list: - # If billing agent, create a sequence - if any( - role and role[2] and role[2].get("role") == "4_mand" - for role in vals.get("acc_operation_role_ids", [False, False, []]) - ): - vals["ref_producer"] = self.env["ir.sequence"].next_by_code( - "res.partner" - ) - result = super().create(vals_list) - return result - - def write(self, vals): - """ - Overwrite write method to initialize ref_producer if empty - """ - if ( - any( - role and role[2] and role[2].get("role") == "4_mand" - for role in vals.get("acc_operation_role_ids", [False, False, []]) - ) - and not self.ref_producer - ): - vals["ref_producer"] = self.env["ir.sequence"].next_by_code("res.partner") - return super().write(vals) def _fields_sync(self, values): res = super()._fields_sync(values)