Merge PR #183 into 14.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2022-07-08 17:37:08 +00:00
4 changed files with 39 additions and 2 deletions

View File

@@ -1,3 +1,4 @@
from . import models from . import models
from . import report from . import report
from . import wizards from . import wizards
from .hooks import pre_init_hook

View File

@@ -41,4 +41,5 @@
], ],
"demo": ["demo/intrastat_demo.xml"], "demo": ["demo/intrastat_demo.xml"],
"installable": True, "installable": True,
"pre_init_hook": "pre_init_hook",
} }

View File

@@ -0,0 +1,35 @@
# Copyright 2022 Stefan Rijnhart <stefan@opener.amsterdam>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
def pre_init_hook(cr):
"""Prepopulate stored computed fields for faster installation"""
logger = logging.getLogger(__name__)
logger.info("Prepopulating stored computed fields")
cr.execute(
"""
alter table account_move
add column if not exists src_dest_country_id integer;
"""
)
cr.execute(
"""
with countries as (
select am.id as move_id,
coalesce(
rps.country_id,
rp.country_id,
rpc.country_id
) as country_id
from account_move am
left join res_partner rps on rps.id = am.partner_shipping_id
join res_partner rp on rp.id = am.partner_id
join res_company rc on rc.id = am.company_id
join res_partner rpc on rpc.id = rc.partner_id
)
update account_move am
set src_dest_country_id = countries.country_id
from countries where am.id = countries.move_id;
"""
)

View File

@@ -978,9 +978,9 @@ class IntrastatProductDeclaration(models.Model):
def create_xls(self): def create_xls(self):
if self.env.context.get("computation_lines"): if self.env.context.get("computation_lines"):
report_file = "instrastat_transactions" report_file = "intrastat_transactions"
else: else:
report_file = "instrastat_declaration_lines" report_file = "intrastat_declaration_lines"
return { return {
"type": "ir.actions.report", "type": "ir.actions.report",
"report_type": "xlsx", "report_type": "xlsx",