summaryrefslogtreecommitdiff
path: root/addons/l10n_fr/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/l10n_fr/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/l10n_fr/models')
-rw-r--r--addons/l10n_fr/models/__init__.py6
-rw-r--r--addons/l10n_fr/models/account_chart_template.py17
-rw-r--r--addons/l10n_fr/models/l10n_fr.py21
-rw-r--r--addons/l10n_fr/models/res_company.py64
4 files changed, 108 insertions, 0 deletions
diff --git a/addons/l10n_fr/models/__init__.py b/addons/l10n_fr/models/__init__.py
new file mode 100644
index 00000000..815ba6b2
--- /dev/null
+++ b/addons/l10n_fr/models/__init__.py
@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import l10n_fr
+from . import account_chart_template
+from . import res_company
diff --git a/addons/l10n_fr/models/account_chart_template.py b/addons/l10n_fr/models/account_chart_template.py
new file mode 100644
index 00000000..c71d8817
--- /dev/null
+++ b/addons/l10n_fr/models/account_chart_template.py
@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, models, fields
+
+
+class AccountChartTemplate(models.Model):
+ _inherit = 'account.chart.template'
+
+ @api.model
+ def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None):
+ journal_data = super(AccountChartTemplate, self)._prepare_all_journals(
+ acc_template_ref, company, journals_dict)
+ for journal in journal_data:
+ if journal['type'] in ('sale', 'purchase') and company.country_id.code == "FR":
+ journal.update({'refund_sequence': True})
+ return journal_data
diff --git a/addons/l10n_fr/models/l10n_fr.py b/addons/l10n_fr/models/l10n_fr.py
new file mode 100644
index 00000000..40acbb6f
--- /dev/null
+++ b/addons/l10n_fr/models/l10n_fr.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo import fields, models, api, _
+
+
+class ResPartner(models.Model):
+ _inherit = 'res.partner'
+
+ siret = fields.Char(string='SIRET', size=14)
+
+class ChartTemplate(models.Model):
+ _inherit = 'account.chart.template'
+
+ def _prepare_all_journals(self, acc_template_ref, company, journals_dict=None):
+ journals = super(ChartTemplate, self)._prepare_all_journals(acc_template_ref, company, journals_dict)
+ if company.country_id.code == "FR":
+ #For France, sale/purchase journals must have a dedicated sequence for refunds
+ for journal in journals:
+ if journal['type'] in ['sale', 'purchase']:
+ journal['refund_sequence'] = True
+ return journals
diff --git a/addons/l10n_fr/models/res_company.py b/addons/l10n_fr/models/res_company.py
new file mode 100644
index 00000000..4088a1af
--- /dev/null
+++ b/addons/l10n_fr/models/res_company.py
@@ -0,0 +1,64 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models, api, _
+
+
+class ResCompany(models.Model):
+ _inherit = 'res.company'
+
+ l10n_fr_closing_sequence_id = fields.Many2one('ir.sequence', 'Sequence to use to build sale closings', readonly=True)
+ siret = fields.Char(related='partner_id.siret', string='SIRET', size=14, readonly=False)
+ ape = fields.Char(string='APE')
+
+ @api.model
+ def _get_unalterable_country(self):
+ return ['FR', 'MF', 'MQ', 'NC', 'PF', 'RE', 'GF', 'GP', 'TF'] # These codes correspond to France and DOM-TOM.
+
+ def _is_vat_french(self):
+ return self.vat and self.vat.startswith('FR') and len(self.vat) == 13
+
+ def _is_accounting_unalterable(self):
+ if not self.vat and not self.country_id:
+ return False
+ return self.country_id and self.country_id.code in self._get_unalterable_country()
+
+ @api.model
+ def create(self, vals):
+ company = super(ResCompany, self).create(vals)
+ #when creating a new french company, create the securisation sequence as well
+ if company._is_accounting_unalterable():
+ sequence_fields = ['l10n_fr_closing_sequence_id']
+ company._create_secure_sequence(sequence_fields)
+ return company
+
+ def write(self, vals):
+ res = super(ResCompany, self).write(vals)
+ #if country changed to fr, create the securisation sequence
+ for company in self:
+ if company._is_accounting_unalterable():
+ sequence_fields = ['l10n_fr_closing_sequence_id']
+ company._create_secure_sequence(sequence_fields)
+ return res
+
+ def _create_secure_sequence(self, sequence_fields):
+ """This function creates a no_gap sequence on each company in self that will ensure
+ a unique number is given to all posted account.move in such a way that we can always
+ find the previous move of a journal entry on a specific journal.
+ """
+ for company in self:
+ vals_write = {}
+ for seq_field in sequence_fields:
+ if not company[seq_field]:
+ vals = {
+ 'name': _('Securisation of %s - %s') % (seq_field, company.name),
+ 'code': 'FRSECURE%s-%s' % (company.id, seq_field),
+ 'implementation': 'no_gap',
+ 'prefix': '',
+ 'suffix': '',
+ 'padding': 0,
+ 'company_id': company.id}
+ seq = self.env['ir.sequence'].create(vals)
+ vals_write[seq_field] = seq.id
+ if vals_write:
+ company.write(vals_write)