Skip to content
Browse files

[FIX] l10n_be_intrastat: example bis change inventory report

closes #31372
  • Loading branch information...
nle-odoo committed Feb 22, 2019
1 parent bed3b4a commit 1b1ca38f082a9f0afbe26b44131219f3a0eb80ee
Showing with 66 additions and 0 deletions.
  1. +1 −0 addons/l10n_be_intrastat/models/
  2. +65 −0 addons/l10n_be_intrastat/models/
@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import l10n_be_intrastat
import report_intrastat
@@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models
from import drop_view_if_exists

class ReportIntrastat(models.Model):
_inherit = "report.intrastat"

def init(self):
drop_view_if_exists(, self._table)"""
create or replace view report_intrastat as (
with category_intrastat as (
select DISTINCT ON(, categs.intrastat_id
from product_category categ
inner join product_category categs on (
categs.intrastat_id is not null and
categs.parent_right > categ.parent_left and categs.parent_left <= categ.parent_left
) order by, categs.parent_left desc
to_char(inv.date_invoice, 'YYYY') as name,
to_char(inv.date_invoice, 'MM') as month,
min( as id,
coalesce(pt.intrastat_id, categ.intrastat_id) as intrastat_id,
upper(inv_country.code) as code,
sum(case when inv_line.price_unit is not null
then inv_line.price_unit * (1.0 - coalesce(, 0.0) / 100.0) * inv_line.quantity
else 0
end) as value,
case when uom.category_id != puom.category_id then (coalesce(nullif(pp.weight, 0), pt.weight) * inv_line.quantity)
else (coalesce(nullif(pp.weight, 0), pt.weight) * inv_line.quantity * uom.factor) end
) as weight,
case when uom.category_id != puom.category_id then inv_line.quantity
else (inv_line.quantity * uom.factor) end
) as supply_units,
inv.currency_id as currency_id,
inv.number as ref,
case when inv.type in ('out_invoice','in_refund')
then 'export'
else 'import'
end as type,
inv.company_id as company_id
account_invoice inv
left join account_invoice_line inv_line on
left join (product_template pt
left join product_product pp on (pp.product_tmpl_id =
on (inv_line.product_id =
left join product_uom uom on
left join product_uom puom on = pt.uom_id
left join category_intrastat categ on = pt.categ_id
left join (res_partner inv_address
left join res_country inv_country on ( = inv_address.country_id))
on ( = coalesce(inv.partner_shipping_id, inv.partner_id))
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'),categ.intrastat_id,inv.type,pt.intrastat_id, inv_country.code,inv.number, inv.currency_id, inv.company_id

0 comments on commit 1b1ca38

Please sign in to comment.
You can’t perform that action at this time.