diff --git a/addons/l10n_be_intrastat/wizard/xml_decl.py b/addons/l10n_be_intrastat/wizard/xml_decl.py index f5b9bdcf6b690..b7c6e04f71324 100644 --- a/addons/l10n_be_intrastat/wizard/xml_decl.py +++ b/addons/l10n_be_intrastat/wizard/xml_decl.py @@ -155,8 +155,8 @@ def _get_lines(self, dispatchmode=False, extendedmode=False): OR (res_country.code is NULL AND countrypartner.code IS NOT NULL AND not countrypartner.code=%s)) AND inv.type IN (%s, %s) - AND to_char(inv.date_invoice, 'YYYY')=%s - AND to_char(inv.date_invoice, 'MM')=%s + AND to_char(COALESCE(inv.date, inv.date_invoice), 'YYYY')=%s + AND to_char(COALESCE(inv.date, inv.date_invoice), 'MM')=%s """ self.env.cr.execute(query, (company.id, company.partner_id.country_id.code, diff --git a/addons/report_intrastat/report/report_intrastat_report.py b/addons/report_intrastat/report/report_intrastat_report.py index 1ca5dfb4bec99..518534d0a9283 100644 --- a/addons/report_intrastat/report/report_intrastat_report.py +++ b/addons/report_intrastat/report/report_intrastat_report.py @@ -30,8 +30,8 @@ def init(self): self.env.cr.execute(""" create or replace view report_intrastat as ( select - to_char(inv.date_invoice, 'YYYY') as name, - to_char(inv.date_invoice, 'MM') as month, + to_char(coalesce(inv.date, inv.date_invoice), 'YYYY') as name, + to_char(coalesce(inv.date, inv.date_invoice), 'MM') as month, min(inv_line.id) as id, intrastat.id as intrastat_id, upper(inv_country.code) as code, @@ -71,5 +71,5 @@ def init(self): inv.state in ('open','paid') and inv_line.product_id is not null and inv_country.intrastat=true - group by to_char(inv.date_invoice, 'YYYY'), to_char(inv.date_invoice, 'MM'),intrastat.id,inv.type,pt.intrastat_id, inv_country.code,inv.number, inv.currency_id, inv.company_id + group by to_char(coalesce(inv.date, inv.date_invoice), 'YYYY'), to_char(coalesce(inv.date, inv.date_invoice), 'MM'),intrastat.id,inv.type,pt.intrastat_id, inv_country.code,inv.number, inv.currency_id, inv.company_id )""")