[FIX] l10n_be_intrastat is back, compliant with the new accounting

This commit is contained in:
pvy-odoo
2015-09-18 17:19:50 +02:00
committed by pvy
parent 61c0e82bdc
commit 642fea43da
5 changed files with 107 additions and 125 deletions
+1 -1
View File
@@ -20,5 +20,5 @@ Based on invoices.
'l10n_be_intrastat.xml',
'wizard/l10n_be_intrastat_xml_view.xml',
],
'installable': False,
'installable': True,
}
+78 -101
View File
@@ -1,185 +1,162 @@
# -*- encoding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp.osv import fields, osv
from openerp import fields, models
class account_invoice(osv.osv):
class account_invoice_line(models.Model):
_inherit = "account.invoice.line"
intrastat_transaction_id = fields.Many2one('l10n_be_intrastat.transaction', 'Intrastat Transaction Type',
help="Intrastat nature of transaction")
class account_invoice(models.Model):
_inherit = "account.invoice"
_columns = {
'incoterm_id': fields.many2one(
'stock.incoterms', 'Incoterm',
help="International Commercial Terms are a series of predefined commercial terms "
"used in international transactions."),
'intrastat_transaction_id': fields.many2one(
'l10n_be_intrastat.transaction', 'Intrastat Transaction Type',
help="Intrastat nature of transaction"),
'transport_mode_id': fields.many2one(
'l10n_be_intrastat.transport_mode', 'Intrastat Transport Mode'),
'intrastat_country_id': fields.many2one(
'res.country', 'Intrastat Country',
help='Intrastat country, delivery for sales, origin for purchases',
domain=[('intrastat','=',True)]),
}
incoterm_id = fields.Many2one('stock.incoterms', 'Incoterm',
help="International Commercial Terms are a series of predefined commercial terms "
"used in international transactions.")
transport_mode_id = fields.Many2one('l10n_be_intrastat.transport_mode', 'Intrastat Transport Mode')
intrastat_country_id = fields.Many2one('res.country', 'Intrastat Country',
help='Intrastat country, delivery for sales, origin for purchases',
domain=[('intrastat', '=', True)])
class intrastat_region(osv.osv):
class intrastat_region(models.Model):
_name = 'l10n_be_intrastat.region'
_columns = {
'code': fields.char('Code', required=True),
'country_id': fields.many2one('res.country', 'Country'),
'name': fields.char('Name', translate=True),
'description': fields.char('Description'),
}
code = fields.Char('Code', required=True)
country_id = fields.Many2one('res.country', 'Country')
name = fields.Char('Name', translate=True)
description = fields.Char('Description')
_sql_constraints = [
('l10n_be_intrastat_regioncodeunique', 'UNIQUE (code)', 'Code must be unique.'),
]
class intrastat_transaction(osv.osv):
class intrastat_transaction(models.Model):
_name = 'l10n_be_intrastat.transaction'
_rec_name = 'code'
_columns = {
'code': fields.char('Code', required=True, readonly=True),
'description': fields.text('Description', readonly=True),
}
code = fields.Char('Code', required=True, readonly=True)
description = fields.Text('Description', readonly=True)
_sql_constraints = [
('l10n_be_intrastat_trcodeunique', 'UNIQUE (code)', 'Code must be unique.'),
]
class intrastat_transport_mode(osv.osv):
class intrastat_transport_mode(models.Model):
_name = 'l10n_be_intrastat.transport_mode'
_columns = {
'code': fields.char('Code', required=True, readonly=True),
'name': fields.char('Description', readonly=True),
}
code = fields.Char('Code', required=True, readonly=True)
name = fields.Char('Description', readonly=True)
_sql_constraints = [
('l10n_be_intrastat_trmodecodeunique', 'UNIQUE (code)', 'Code must be unique.'),
]
class product_category(osv.osv):
class product_category(models.Model):
_name = "product.category"
_inherit = "product.category"
_columns = {
'intrastat_id': fields.many2one('report.intrastat.code', 'Intrastat Code'),
}
intrastat_id = fields.Many2one('report.intrastat.code', 'Intrastat Code')
def get_intrastat_recursively(self, cr, uid, category, context=None):
def get_intrastat_recursively(self):
""" Recursively search in categories to find an intrastat code id
:param category : Browse record of a category
"""
if category.intrastat_id:
res = category.intrastat_id.id
elif category.parent_id:
res = self.get_intrastat_recursively(cr, uid, category.parent_id, context=context)
if self.intrastat_id:
res = self.intrastat_id.id
elif self.parent_id:
res = self.parent_id.get_intrastat_recursively()
else:
res = None
return res
class product_product(osv.osv):
class product_product(models.Model):
_name = "product.product"
_inherit = "product.product"
def get_intrastat_recursively(self, cr, uid, id, context=None):
def get_intrastat_recursively(self):
""" Recursively search in categories to find an intrastat code id
"""
product = self.browse(cr, uid, id, context=context)
if product.intrastat_id:
res = product.intrastat_id.id
elif product.categ_id:
res = self.pool['product.category'].get_intrastat_recursively(
cr, uid, product.categ_id, context=context)
if self.intrastat_id:
res = self.intrastat_id.id
elif self.categ_id:
res = self.categ_id.get_intrastat_recursively()
else:
res = None
return res
class purchase_order(osv.osv):
class purchase_order(models.Model):
_inherit = "purchase.order"
def _prepare_invoice(self, cr, uid, order, line_ids, context=None):
def _prepare_invoice(self):
"""
copy incoterm from purchase order to invoice
"""
invoice = super(purchase_order, self)._prepare_invoice(
cr, uid, order, line_ids, context=context)
if order.incoterm_id:
invoice['incoterm_id'] = order.incoterm_id.id
invoice = super(purchase_order, self)._prepare_invoice()
if self.incoterm_id:
invoice['incoterm_id'] = self.incoterm_id.id
#Try to determine products origin
if order.partner_id.country_id:
if self.partner_id.country_id:
#It comes from vendor
invoice['intrastat_country_id'] = order.partner_id.country_id.id
invoice['intrastat_country_id'] = self.partner_id.country_id.id
return invoice
class report_intrastat_code(osv.osv):
class report_intrastat_code(models.Model):
_inherit = "report.intrastat.code"
_columns = {
'description': fields.text('Description', translate=True),
}
description = fields.Text('Description', translate=True)
class res_company(osv.osv):
class res_company(models.Model):
_inherit = "res.company"
_columns = {
'region_id': fields.many2one('l10n_be_intrastat.region', 'Intrastat region'),
'transport_mode_id': fields.many2one('l10n_be_intrastat.transport_mode',
'Default transport mode'),
'incoterm_id': fields.many2one('stock.incoterms', 'Default incoterm for Intrastat',
region_id = fields.Many2one('l10n_be_intrastat.region', 'Intrastat region')
transport_mode_id = fields.Many2one('l10n_be_intrastat.transport_mode',
'Default transport mode')
incoterm_id = fields.Many2one('stock.incoterms', 'Default incoterm for Intrastat',
help="International Commercial Terms are a series of "
"predefined commercial terms used in international "
"transactions."),
}
"transactions.")
class sale_order(osv.osv):
class sale_order(models.Model):
_inherit = "sale.order"
def _prepare_invoice(self, cr, uid, saleorder, lines, context=None):
def _prepare_invoice(self):
"""
copy incoterm from sale order to invoice
"""
invoice = super(sale_order, self)._prepare_invoice(
cr, uid, saleorder, lines, context=context)
if saleorder.incoterm:
invoice['incoterm_id'] = saleorder.incoterm.id
invoice = super(sale_order, self)._prepare_invoice()
if self.incoterm:
invoice['incoterm_id'] = self.incoterm.id
# Guess products destination
if saleorder.partner_shipping_id.country_id:
invoice['intrastat_country_id'] = saleorder.partner_shipping_id.country_id.id
elif saleorder.partner_id.country_id:
invoice['intrastat_country_id'] = saleorder.partner_id.country_id.id
elif saleorder.partner_invoice_id.country_id:
invoice['intrastat_country_id'] = saleorder.partner_invoice_id.country_id.id
if self.partner_shipping_id.country_id:
invoice['intrastat_country_id'] = self.partner_shipping_id.country_id.id
elif self.partner_id.country_id:
invoice['intrastat_country_id'] = self.partner_id.country_id.id
elif self.partner_invoice_id.country_id:
invoice['intrastat_country_id'] = self.partner_invoice_id.country_id.id
return invoice
class stock_warehouse(osv.osv):
class stock_warehouse(models.Model):
_inherit = "stock.warehouse"
_columns = {
'region_id': fields.many2one('l10n_be_intrastat.region', 'Intrastat region'),
}
def get_regionid_from_locationid(self, cr, uid, location_id, context=None):
location_model = self.pool['stock.location']
region_id = fields.Many2one('l10n_be_intrastat.region', 'Intrastat region')
location = location_model.browse(cr, uid, location_id, context=context)
location_ids = location_model.search(cr, uid,
[('parent_left', '<=', location.parent_left),
('parent_right', '>=', location.parent_right)],
context=context)
warehouse_ids = self.search(cr, uid,
[('lot_stock_id', 'in', location_ids),
('region_id', '!=', False)],
context=context)
warehouses = self.browse(cr, uid, warehouse_ids, context=context)
def get_regionid_from_locationid(self, location):
location_ids = location.search([('parent_left', '<=', location.parent_left), ('parent_right', '>=', location.parent_right)])
warehouses = self.search([('lot_stock_id', 'in', location_ids.ids), ('region_id', '!=', False)])
if warehouses and warehouses[0]:
return warehouses[0].region_id.id
return None
+17 -5
View File
@@ -11,7 +11,6 @@
<field name="incoterm_id" groups="l10n_be_intrastat.intrastat_extended"/>
</xpath>
<xpath expr="//field[@name='move_id']" position="after">
<field name="intrastat_transaction_id"/>
<field name="transport_mode_id" groups="l10n_be_intrastat.intrastat_extended"/>
<field name="intrastat_country_id"/>
</xpath>
@@ -77,8 +76,8 @@
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='parent']" position="inside">
<group string="Intrastat" colspan="2">
<xpath expr="//group[@name='first']" position="after">
<group string="Intrastat">
<field name="intrastat_id"/>
</group>
</xpath>
@@ -121,13 +120,26 @@
<xpath expr="//field[@name='payment_term_id']" position="after">
<field name="incoterm_id" groups="l10n_be_intrastat.intrastat_extended"/>
</xpath>
<xpath expr="//field[@name='period_id']" position="after">
<field name="intrastat_transaction_id" />
<xpath expr="//field[@name='date_due']" position="after">
<field name="transport_mode_id" groups="l10n_be_intrastat.intrastat_extended"/>
<field name="intrastat_country_id" />
</xpath>
</field>
</record>
<!-- Invoice Line Form -->
<record id="l10n_be_intrastat_xml_decl_invoice_line_view" model="ir.ui.view">
<field name="name">l10n_be_intrastat_xml.invoiceline_form</field>
<field name="model">account.invoice.line</field>
<field name="inherit_id" ref="account.view_invoice_line_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='discount']" position="after">
<field name="intrastat_transaction_id" />
</xpath>
</field>
</record>
</data>
</openerp>
@@ -14,7 +14,7 @@
<group>
<field name="month"/>
<field name="year"/>
<field name="tax_code_id"/>
<field name="company_id"/>
</group>
<group>
<field name="arrivals"/>
@@ -50,7 +50,7 @@
<menuitem
name="Intrastat Declaration"
parent="l10n_be.menu_finance_belgian_statement"
parent="l10n_be.account_reports_be_statements_menu"
action="action_intrastat_xml_declaration"
id="l10n_be_intrastat_xml_declaration"
groups="account.group_account_manager"/>
+9 -16
View File
@@ -19,14 +19,8 @@ class xml_decl(osv.TransientModel):
_name = "l10n_be_intrastat_xml.xml_decl"
_description = 'Intrastat XML Declaration'
def _get_tax_code(self, cr, uid, context=None):
obj_tax_code = self.pool.get('account.tax.code')
obj_user = self.pool.get('res.users')
company_id = obj_user.browse(cr, uid, uid, context=context).company_id.id
tax_code_ids = obj_tax_code.search(cr, uid, [('company_id', '=', company_id),
('parent_id', '=', False)],
context=context)
return tax_code_ids and tax_code_ids[0] or False
def _get_company_id(self, cr, uid, context=None):
return self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.id
def _get_def_monthyear(self, cr, uid, context=None):
td = datetime.strptime(fields.date.context_today(self, cr, uid, context=context),
@@ -46,8 +40,7 @@ class xml_decl(osv.TransientModel):
('08','August'), ('09','September'), ('10','October'),
('11','November'), ('12','December')], 'Month', required=True),
'year': fields.char('Year', size=4, required=True),
'tax_code_id': fields.many2one('account.tax.code', 'Company Tax Chart',
domain=[('parent_id', '=', False)], required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'arrivals': fields.selection([('be-exempt', 'Exempt'),
('be-standard', 'Standard'),
('be-extended', 'Extended')],
@@ -64,26 +57,26 @@ class xml_decl(osv.TransientModel):
'arrivals': 'be-standard',
'dispatches': 'be-standard',
'name': 'intrastat.xml',
'tax_code_id': _get_tax_code,
'company_id': _get_company_id,
'month': _get_def_month,
'year': _get_def_year,
'state': 'draft',
}
def _company_warning(self, cr, uid, translated_msg, context=None):
""" Raise a error with custom message, asking user to configure company settings """
xmlid_mod = self.pool['ir.model.data']
action_id = xmlid_mod.xmlid_to_res_id(cr, uid, 'base.action_res_company_form')
raise exceptions.RedirectWarning(
translated_msg, action_id, _('Go to company configuration screen'))
def create_xml(self, cr, uid, ids, context=None):
"""Creates xml that is to be exported and sent to estate for partner vat intra.
:return: Value for next action.
:rtype: dict
"""
decl_datas = self.browse(cr, uid, ids[0])
company = decl_datas.tax_code_id.company_id
company = decl_datas.company_id
if not (company.partner_id and company.partner_id.country_id and
company.partner_id.country_id.id):
self._company_warning(
@@ -213,8 +206,8 @@ class xml_decl(osv.TransientModel):
for inv_line in invoicelines:
#Check type of transaction
if inv_line.invoice_id.intrastat_transaction_id:
extta = inv_line.invoice_id.intrastat_transaction_id.code
if inv_line.intrastat_transaction_id:
extta = inv_line.intrastat_transaction_id.code
else:
extta = "1"
#Check country