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 e662562
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 61 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 <alexis.delattre@akretion.com>
# 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 <alexis.delattre@akretion.com>
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 <alexis.delattre@akretion.com>
# 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
89 changes: 50 additions & 39 deletions l10n_fr_das2/models/l10n_fr_das2.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,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 +77,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 +99,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 +131,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 +239,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 @@ -292,12 +297,13 @@ def _prepare_line(self, partner, base_domain):
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,
_(
"Payment dated %(date)s in journal '%(journal)s': "
"%(amount).2f € (journal entry %(move_name)s)",
date=mline.date,
journal=mline.journal_id.display_name,
amount=mline.balance,
move_name=mline.move_id.name,
)
)
res = False
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,7 +884,7 @@ 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)
state = fields.Selection(related="parent_id.state", store=True)
note = fields.Text()
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.
12 changes: 6 additions & 6 deletions l10n_fr_das2/views/l10n_fr_das2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<field name="name">l10n.fr.das2.form</field>
<field name="model">l10n.fr.das2</field>
<field name="arch" type="xml">
<form string="DAS2">
<form>
<header>
<button
name="generate_lines"
Expand Down Expand Up @@ -95,7 +95,7 @@
<field name="name">l10n.fr.das2.tree</field>
<field name="model">l10n.fr.das2</field>
<field name="arch" type="xml">
<tree string="DAS2">
<tree>
<field name="year" decoration-bf="1" />
<field name="company_id" groups="base.group_multi_company" />
<field name="currency_id" invisible="1" />
Expand All @@ -113,7 +113,7 @@
<field name="name">l10n.fr.das2.search</field>
<field name="model">l10n.fr.das2</field>
<field name="arch" type="xml">
<search string="Search DAS2">
<search>
<field name="year" />
<filter name="draft" string="Draft" domain="[('state', '=', 'draft')]" />
<filter name="done" string="Done" domain="[('state', '=', 'done')]" />
Expand All @@ -139,7 +139,7 @@
<field name="name">l10n.fr.das2.line.form</field>
<field name="model">l10n.fr.das2.line</field>
<field name="arch" type="xml">
<form string="DAS2 Line">
<form>
<group name="main">
<group name="left">
<field
Expand Down Expand Up @@ -211,7 +211,7 @@
<field name="name">l10n.fr.das2.line.tree</field>
<field name="model">l10n.fr.das2.line</field>
<field name="arch" type="xml">
<tree string="DAS2 Lines" decoration-muted="to_declare == False">
<tree decoration-muted="to_declare == False">
<field name="partner_id" />
<field name="partner_siret" />
<field name="job" />
Expand All @@ -237,7 +237,7 @@
<field name="name">l10n.fr.das2.line.search</field>
<field name="model">l10n.fr.das2.line</field>
<field name="arch" type="xml">
<search string="Search DAS2 Lines">
<search>
<field name="partner_id" />
<separator />
<filter
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# generated from manifests external_dependencies
pgpy
python-stdnum
python-stdnum>=1.18
requests_oauthlib
unidecode
1 change: 1 addition & 0 deletions setup/l10n_fr_cog/odoo/addons/l10n_fr_cog
6 changes: 6 additions & 0 deletions setup/l10n_fr_cog/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions setup/l10n_fr_das2/odoo/addons/l10n_fr_das2
6 changes: 6 additions & 0 deletions setup/l10n_fr_das2/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit e662562

Please sign in to comment.