Skip to content

Commit

Permalink
[MIG] l10n_fr_das2 and l10n_fr_cog to v15
Browse files Browse the repository at this point in the history
Improve DAS2 readme
  • Loading branch information
alexis-via committed Apr 7, 2023
1 parent ef52e50 commit fc7eb8a
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 67 deletions.
4 changes: 2 additions & 2 deletions l10n_fr_cog/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2020-2021 Akretion France (http://www.akretion.com/)
# Copyright 2020-2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Code Officiel Géographique",
"summary": "Add Code Officiel Géographique (COG) on countries",
"version": "14.0.1.0.0",
"version": "15.0.1.0.0",
"category": "French Localization",
"author": "Akretion,Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
Expand Down
21 changes: 10 additions & 11 deletions l10n_fr_cog/post_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ def set_fr_cog(cr, registry):
if xfield.attrib and xfield.attrib.get("name") == "fr_cog":
data[xmlid] = int(xfield.text)
logger.debug("set_fr_cog data=%s", data)
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
for xmlid, fr_cog in data.items():
country = env.ref(xmlid)
country.fr_cog = fr_cog
logger.debug(
"Country ID %d xmlid %s updated with fr_cog=%d",
country.id,
xmlid,
fr_cog,
)
env = api.Environment(cr, SUPERUSER_ID, {})
for xmlid, fr_cog in data.items():
country = env.ref(xmlid)
country.fr_cog = fr_cog
logger.debug(
"Country ID %d xmlid %s updated with fr_cog=%d",
country.id,
xmlid,
fr_cog,
)
return
12 changes: 11 additions & 1 deletion l10n_fr_cog/views/country.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2020-2021 Akretion France (http://www.akretion.com/)
Copyright 2020-2023 Akretion France (http://www.akretion.com/)
@author: Alexis de Lattre <[email protected]>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
Expand All @@ -18,5 +18,15 @@
</field>
</record>

<record id="view_country_tree" model="ir.ui.view">
<field name="model">res.country</field>
<field name="inherit_id" ref="base.view_country_tree" />
<field name="arch" type="xml">
<field name="code" position="after">
<field name="fr_cog" optional="hide" />
</field>
</field>
</record>


</odoo>
4 changes: 2 additions & 2 deletions l10n_fr_das2/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2020-2021 Akretion France (http://www.akretion.com/)
# Copyright 2020-2023 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "DAS2",
"version": "14.0.2.0.0",
"version": "15.0.1.0.0",
"category": "Invoicing Management",
"license": "AGPL-3",
"summary": "DAS2 (France)",
Expand Down
99 changes: 55 additions & 44 deletions l10n_fr_das2/models/l10n_fr_das2.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from odoo import _, api, fields, models, tools
from odoo.exceptions import UserError, ValidationError
from odoo.tools.misc import format_amount, format_date

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -61,13 +62,14 @@ class L10nFrDas2(models.Model):
_inherit = ["mail.thread", "mail.activity.mixin"]
_order = "year desc"
_description = "DAS2"
_check_company_auto = True

year = fields.Integer(
string="Year",
required=True,
states={"done": [("readonly", True)]},
tracking=True,
default=lambda self: self._default_year(),
index=True,
)
state = fields.Selection(
[
Expand All @@ -76,20 +78,18 @@ class L10nFrDas2(models.Model):
],
default="draft",
readonly=True,
string="State",
tracking=True,
index=True,
)
company_id = fields.Many2one(
"res.company",
string="Company",
ondelete="cascade",
required=True,
states={"done": [("readonly", True)]},
default=lambda self: self.env.company,
)
currency_id = fields.Many2one(
related="company_id.currency_id",
readonly=True,
store=True,
string="Company Currency",
)
Expand All @@ -100,6 +100,7 @@ class L10nFrDas2(models.Model):
default=lambda self: self._default_payment_journals(),
domain="[('company_id', '=', company_id)]",
states={"done": [("readonly", True)]},
check_company=True,
)
line_ids = fields.One2many(
"l10n.fr.das2.line",
Expand Down Expand Up @@ -131,7 +132,7 @@ class L10nFrDas2(models.Model):
help="Contact in the company for the fiscal administration: the name, "
"email and phone number of this partner will be used in the file.",
)
attachment_id = fields.Many2one("ir.attachment", string="Attachment", readonly=True)
attachment_id = fields.Many2one("ir.attachment", readonly=True)
attachment_datas = fields.Binary(
related="attachment_id.datas", string="File Export"
)
Expand Down Expand Up @@ -239,15 +240,20 @@ def generate_lines(self):
if company.country_id.code not in FRANCE_CODES:
raise UserError(
_(
"Company '%s' is configured in country '%s'. The DAS2 is "
"only for France and it's oversea territories."
"Company '%(company)s' is configured in country '%(country)s'. "
"The DAS2 is only for France and it's oversea territories.",
company=company.display_name,
country=company.country_id.name,
)
% (company.display_name, company.country_id.name)
)
if company.currency_id != self.env.ref("base.EUR"):
raise UserError(
_("Company '%s' is configured with currency '%s'. " "It should be EUR.")
% (company.display_name, company.currency_id.name)
_(
"Company '%(company)s' is configured with currency '%(currency)s'. "
"It should be EUR.",
company=company.display_name,
currency=company.currency_id.name,
)
)
if company.fr_das2_partner_declare_threshold <= 0:
raise UserError(
Expand Down Expand Up @@ -287,19 +293,19 @@ def _prepare_line(self, partner, base_domain):
("account_id", "=", partner.property_account_payable_id.id),
]
)
note = []
note = ""
amount = 0.0
for mline in mlines:
amount += mline.balance
note.append(
_("Payment dated %s in journal '%s': " "%.2f € (journal entry %s)")
% (
mline.date,
mline.journal_id.display_name,
mline.balance,
mline.move_id.name,
)
note_text = _(
"Payment dated <b>%(date)s</b> in journal <b>%(journal)s</b>: "
"%(amount)s (journal entry %(move_name)s)",
date=format_date(self.env, mline.date),
journal=mline.journal_id.display_name,
amount=format_amount(self.env, mline.balance, self.currency_id),
move_name=mline.move_id.name,
)
note += "<li>%s</li>" % note_text
res = False
amount_int = int(round(amount))
if note and amount_int > 0:
Expand All @@ -309,7 +315,7 @@ def _prepare_line(self, partner, base_domain):
"parent_id": self.id,
"partner_id": partner.id,
"job": partner.fr_das2_job,
"note": "\n".join(note),
"note": "<ul>%s</ul>" % note,
}
if partner.siren and partner.nic:
res["partner_siret"] = partner.siret
Expand Down Expand Up @@ -387,31 +393,39 @@ def _prepare_field(
if not isinstance(value, int):
try:
value = int(value)
except Exception:
except Exception as e:
raise UserError(
_("Failed to convert field '%s' (partner %s) " "to integer.")
% (field_name, partner.display_name)
)
_(
"Failed to convert field '%(field_name)s' "
"(partner %(partner)s) to integer.",
field_name=field_name,
partner=partner.display_name,
)
) from e
value = str(value)
if len(value) > size:
raise UserError(
_(
"Field %s (partner %s) has value %s: "
"it is bigger than the maximum size "
"(%d characters)"
"Field %(field_name)s (partner %(partner)s) has value "
"%(value)s: it is bigger than the maximum size "
"(%(size)d characters).",
field_name=field_name,
partner=partner.display_name,
value=value,
size=size,
)
% (field_name, partner.display_name, value, size)
)
if len(value) < size:
value = value.rjust(size, "0")
return value
if required and not value:
raise UserError(
_(
"The field '%s' (partner %s) is empty or 0. "
"It should have a non-null value."
"The field '%(field_name)s' (partner %(partner)s) is empty or 0. "
"It should have a non-null value.",
field_name=field_name,
partner=partner.display_name,
)
% (field_name, partner.display_name)
)
if not value:
value = " " * size
Expand Down Expand Up @@ -673,10 +687,11 @@ def _prepare_file(self):
if len(fline) != 672:
raise UserError(
_(
"One of the lines has a length of %d. "
"All lines should have a length of 672. Line: %s."
"One of the lines has a length of %(length)d. "
"All lines should have a length of 672. Line: %(line_content)s.",
length=len(fline),
line_content=fline,
)
% (len(fline), fline)
)
file_content = "\r\n".join(flines) + "\r\n"
return file_content
Expand Down Expand Up @@ -722,14 +737,14 @@ def generate_file(self, encryption="prod"):
file_content = self._prepare_file()
try:
file_content_encoded = file_content.encode("latin1")
except UnicodeEncodeError:
except UnicodeEncodeError as e:
raise UserError(
_(
"A special character in the DAS2 file is not in the latin1 "
"table. Please locate this special character and replace "
"it by a standard character and try again."
)
)
) from e

if encryption in ("prod", "test"):
prefix = "DSAL_"
Expand Down Expand Up @@ -798,13 +813,10 @@ class L10nFrDas2Line(models.Model):
partner_siret = fields.Char(
string="SIRET", size=14, states={"done": [("readonly", True)]}
)
company_id = fields.Many2one(
related="parent_id.company_id", store=True, readonly=True
)
company_id = fields.Many2one(related="parent_id.company_id", store=True)
currency_id = fields.Many2one(
related="parent_id.company_id.currency_id",
store=True,
readonly=True,
string="Company Currency",
)
fee_amount = fields.Integer(
Expand Down Expand Up @@ -842,12 +854,11 @@ class L10nFrDas2Line(models.Model):
)
total_amount = fields.Integer(
compute="_compute_total_amount",
string="Total Amount",
store=True,
readonly=True,
)
to_declare = fields.Boolean(
compute="_compute_total_amount", string="To Declare", readonly=True, store=True
compute="_compute_total_amount", readonly=True, store=True
)
allowance_fixed = fields.Boolean(
"Allocation forfaitaire", states={"done": [("readonly", True)]}
Expand All @@ -873,8 +884,8 @@ class L10nFrDas2Line(models.Model):
benefits_in_kind_nict = fields.Boolean(
"Outils issus des NTIC", states={"done": [("readonly", True)]}
)
state = fields.Selection(related="parent_id.state", store=True, readonly=True)
note = fields.Text()
state = fields.Selection(related="parent_id.state", store=True)
note = fields.Html()
job = fields.Char(
string="Profession", size=30, states={"done": [("readonly", True)]}
)
Expand Down
8 changes: 8 additions & 0 deletions l10n_fr_das2/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,11 @@ On the supplier form view, in the *Accounting* tab, you will see a section *DAS2
On the company configuration form, the APE code, SIRET and address must be set.

For the user responsible for the declaration, the phone number and email must be set on his related partner form (name, email and phone number are used in the DAS2 declaration file).

If you want to encrypt the declaration file with the DGFiP's **test** PGP key, ensure that your Odoo server configuration file has the following parameter:

.. code::
running_env = test
Otherwise, Odoo will use DGFiP's **production** PGP key.
Loading

0 comments on commit fc7eb8a

Please sign in to comment.