From 642fea43da39cd5b7262b7ba9caf5ce6e8a9ad65 Mon Sep 17 00:00:00 2001 From: pvy-odoo Date: Thu, 17 Sep 2015 22:16:51 +0200 Subject: [PATCH] [FIX] l10n_be_intrastat is back, compliant with the new accounting --- addons/l10n_be_intrastat/__openerp__.py | 2 +- addons/l10n_be_intrastat/l10n_be_intrastat.py | 179 ++++++++---------- .../l10n_be_intrastat/l10n_be_intrastat.xml | 22 ++- .../wizard/l10n_be_intrastat_xml_view.xml | 4 +- addons/l10n_be_intrastat/wizard/xml_decl.py | 25 +-- 5 files changed, 107 insertions(+), 125 deletions(-) diff --git a/addons/l10n_be_intrastat/__openerp__.py b/addons/l10n_be_intrastat/__openerp__.py index b623197af1e..e02d2bc95e9 100644 --- a/addons/l10n_be_intrastat/__openerp__.py +++ b/addons/l10n_be_intrastat/__openerp__.py @@ -20,5 +20,5 @@ Based on invoices. 'l10n_be_intrastat.xml', 'wizard/l10n_be_intrastat_xml_view.xml', ], - 'installable': False, + 'installable': True, } diff --git a/addons/l10n_be_intrastat/l10n_be_intrastat.py b/addons/l10n_be_intrastat/l10n_be_intrastat.py index 0a5f0f6b563..57ebb637d4d 100644 --- a/addons/l10n_be_intrastat/l10n_be_intrastat.py +++ b/addons/l10n_be_intrastat/l10n_be_intrastat.py @@ -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 diff --git a/addons/l10n_be_intrastat/l10n_be_intrastat.xml b/addons/l10n_be_intrastat/l10n_be_intrastat.xml index eeeeeff98c2..437e7ec81ca 100644 --- a/addons/l10n_be_intrastat/l10n_be_intrastat.xml +++ b/addons/l10n_be_intrastat/l10n_be_intrastat.xml @@ -11,7 +11,6 @@ - @@ -77,8 +76,8 @@ product.category - - + + @@ -121,13 +120,26 @@ - - + + + + + l10n_be_intrastat_xml.invoiceline_form + account.invoice.line + + + + + + + + + diff --git a/addons/l10n_be_intrastat/wizard/l10n_be_intrastat_xml_view.xml b/addons/l10n_be_intrastat/wizard/l10n_be_intrastat_xml_view.xml index e3f0f1674f5..f79ee2401ff 100644 --- a/addons/l10n_be_intrastat/wizard/l10n_be_intrastat_xml_view.xml +++ b/addons/l10n_be_intrastat/wizard/l10n_be_intrastat_xml_view.xml @@ -14,7 +14,7 @@ - + @@ -50,7 +50,7 @@ diff --git a/addons/l10n_be_intrastat/wizard/xml_decl.py b/addons/l10n_be_intrastat/wizard/xml_decl.py index ca2eec14de4..002c6485ed6 100644 --- a/addons/l10n_be_intrastat/wizard/xml_decl.py +++ b/addons/l10n_be_intrastat/wizard/xml_decl.py @@ -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