Skip to content

Commit

Permalink
[MIG] l10n_fr_intrastat_service to v17
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-via committed Jan 19, 2024
1 parent 1b1a6ac commit f12ba14
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 59 deletions.
3 changes: 2 additions & 1 deletion l10n_fr_intrastat_service/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "DES",
"version": "16.0.1.4.0",
"version": "17.0.1.0.0",
"category": "Localisation/Report Intrastat",
"license": "AGPL-3",
"summary": "Module for Intrastat service reporting (DES) for France",
Expand All @@ -15,6 +15,7 @@
"external_dependencies": {"python": ["stdnum"]},
"data": [
"security/ir.model.access.csv",
"report/report.xml",
"views/intrastat_service_view.xml",
"data/ir_cron.xml",
"data/mail_template.xml",
Expand Down
30 changes: 9 additions & 21 deletions l10n_fr_intrastat_service/models/intrastat_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ def _check_start_date(self):

@api.depends("declaration_line_ids.amount_company_currency")
def _compute_numbers(self):
rg_res = self.env["l10n.fr.intrastat.service.declaration.line"].read_group(
rg_res = self.env["l10n.fr.intrastat.service.declaration.line"]._read_group(
[("parent_id", "in", self.ids)],
["parent_id", "amount_company_currency"],
["parent_id"],
groupby=["parent_id"],
aggregates=["amount_company_currency:sum", "id:count"],
)
data = {
x["parent_id"][0]: {
"total_amount": x["amount_company_currency"],
"num_decl_lines": x["parent_id_count"],
decl.id: {
"total_amount": total_amount,
"num_decl_lines": line_count,
}
for x in rg_res
for (decl, total_amount, line_count) in rg_res
}
for rec in self:
rec.total_amount = data.get(rec.id, {}).get("total_amount", 0)
Expand Down Expand Up @@ -139,11 +139,9 @@ def unlink(self):
return super().unlink()

@api.depends("year_month")
def name_get(self):
res = []
def _compute_display_name(self):
for rec in self:
res.append((rec.id, "DES %s" % rec.year_month))
return res
rec.display_name = "DES %s" % rec.year_month

def _prepare_domain(self):
self.ensure_one()
Expand Down Expand Up @@ -429,16 +427,6 @@ def _scheduler_reminder(self):
logger.info("End of the DES reminder")
return

def create_xlsx(self):
action = {
"type": "ir.actions.report",
"report_type": "xlsx",
"report_name": "l10n.fr.intrastat.service.declaration.xlsx",
"context": dict(self.env.context),
"data": {"dynamic_report": True},
}
return action


class L10nFrIntrastatServiceDeclarationLine(models.Model):
_name = "l10n.fr.intrastat.service.declaration.line"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class IntrastatServiceDeclarationXlsx(models.AbstractModel):
_name = "report.l10n.fr.intrastat.service.declaration.xlsx"
_name = "report.l10n_fr_intrastat_service.xlsx"
_inherit = "report.report_xlsx.abstract"
_description = "DES XLSX Export"

Expand Down Expand Up @@ -55,7 +55,7 @@ def _get_ws_params(self, wb, data, declaration):
"value": _("Invoice"),
},
"line": {
"value": self._render("line.move_id.name or ''"),
"value": self._render("line.move_id.display_name or ''"),
},
"width": 20,
},
Expand Down
50 changes: 19 additions & 31 deletions l10n_fr_intrastat_service/tests/test_fr_intrastat_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,39 @@
from dateutil.relativedelta import relativedelta
from lxml import etree

from odoo import Command
from odoo.exceptions import UserError
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
from odoo.tools import float_compare

from odoo.addons.account.tests.common import AccountTestInvoicingCommon


@tagged("post_install", "-at_install")
class TestFrIntrastatService(TransactionCase):
class TestFrIntrastatService(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
# Set company country to France
# Using base.main_company is more difficult now because
# its currency is USD
# So I decided to create another company from scratch
cls.company = cls.env["res.company"].create(
cls.fr_test_company = cls.setup_company_data(
"Akretion France",
chart_template=chart_template_ref,
country_id=cls.env.ref("base.fr").id,
vat="FR86792377731",
)
cls.company = cls.fr_test_company["company"]
cls.user.write(
{
"name": "Akretion France",
"street": "27 rue Henri Rolland",
"zip": "69100",
"city": "Villeurbanne",
"country_id": cls.env.ref("base.fr").id,
"vat": "FR86792377731",
"company_ids": [Command.link(cls.company.id)],
"company_id": cls.company.id,
}
)
cls.env.company.chart_template_id.try_loading(company=cls.company)
cls.env.user.write({"company_ids": [(4, cls.company.id)]})
cls.env.user.write({"company_id": cls.company.id})
cls.fp_eu_b2b = cls.env["account.fiscal.position"].create(
{
"name": "EU B2B",
"intrastat": "b2b",
"vat_required": True,
"company_id": cls.company.id,
}
)
cls.move_model = cls.env["account.move"]
Expand Down Expand Up @@ -70,18 +69,7 @@ def setUpClass(cls):
"company_id": False,
}
)
cls.account_revenue = cls.account_account_model.search(
[("code", "=", "706000"), ("company_id", "=", cls.company.id)], limit=1
)
if not cls.account_revenue:
cls.account_revenue = cls.account_account_model.create(
{
"code": "706000",
"name": "Service Sales - (test)",
"user_type_id": cls.ref("account.data_account_type_revenue"),
"company_id": cls.company.id,
}
)
cls.account_revenue = cls.fr_test_company["default_account_revenue"]

# create first invoice
date = datetime.today() + relativedelta(day=5, months=-1)
Expand Down Expand Up @@ -208,4 +196,4 @@ def test_generate_des(self):
self.assertEqual(des.state, "draft")

def test_cron(self):
self.env["l10n.fr.intrastat.service.declaration"]._scheduler_reminder()
self.env["l10n.fr.intrastat.service.declaration"].sudo()._scheduler_reminder()
12 changes: 8 additions & 4 deletions l10n_fr_intrastat_service/views/intrastat_service_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@
name="generate_service_lines"
string="Generate Lines from Invoices"
type="object"
states="draft"
invisible="state != 'draft'"
class="btn-primary"
/>
<button
name="done"
string="Confirm"
type="object"
states="draft"
invisible="state != 'draft'"
class="btn-primary"
/>
<button name="create_xlsx" type="object" string="Excel Export" />
<button
name="%(xlsx_report)d"
type="action"
string="Excel Export"
/>
<button
name="back2draft"
string="Back to Draft"
type="object"
states="done"
invisible="state != 'done'"
confirm="Are you sure you want to go back to draft?"
/>
<field name="state" widget="statusbar" />
Expand Down

0 comments on commit f12ba14

Please sign in to comment.