diff --git a/inter_company_rules/README.rst b/inter_company_rules/README.rst index 746d0a95aa6..2f47fbcee9c 100644 --- a/inter_company_rules/README.rst +++ b/inter_company_rules/README.rst @@ -50,6 +50,7 @@ Contributors * Odoo S.A. * Chafique Delli * Alexis de Lattre +* Lorenzo Battistini Maintainer ---------- diff --git a/inter_company_rules/__openerp__.py b/inter_company_rules/__openerp__.py index 04f3f546fb0..8f8874c0fb6 100644 --- a/inter_company_rules/__openerp__.py +++ b/inter_company_rules/__openerp__.py @@ -20,17 +20,11 @@ ############################################################################## { 'name': 'Inter Company Module for Sale/Purchase Orders and Invoices', - 'version': '1.1', + 'version': '8.0.1.1.0', 'summary': 'Intercompany SO/PO/INV rules', - 'description': ''' Module for synchronization of Documents - between several companies. For example, - this allow you to have a Sale Order created automatically - when a Purchase Order is validated with another company of the system - as supplier, and inversely. - Supported documents are SO, PO and invoices/refunds. -''', - 'author': 'Odoo SA', + 'author': 'Odoo SA, Odoo Community Association (OCA)', 'website': 'http://www.odoo.com', + 'license': 'AGPL-3', 'depends': [ 'sale', 'purchase', diff --git a/inter_company_rules/models/account_invoice.py b/inter_company_rules/models/account_invoice.py index 6527242c1d6..6f73a8468af 100644 --- a/inter_company_rules/models/account_invoice.py +++ b/inter_company_rules/models/account_invoice.py @@ -3,7 +3,7 @@ from openerp.exceptions import Warning as UserError -class account_invoice(models.Model): +class AccountInvoice(models.Model): _inherit = 'account.invoice' @@ -40,7 +40,7 @@ def invoice_validate(self): invoice.inter_company_create_invoice(company, 'out_refund', 'sale_refund') - return super(account_invoice, self).invoice_validate() + return super(AccountInvoice, self).invoice_validate() @api.one def inter_company_create_invoice(self, company, inv_type, journal_type): @@ -219,10 +219,12 @@ def action_cancel(self): for invoice in self: company = self.env['res.company']._find_company_from_partner( invoice.partner_id.id) - if (company and company.intercompany_user_id - and not invoice.auto_generated): + if ( + company and company.intercompany_user_id and not + invoice.auto_generated + ): intercompany_uid = company.intercompany_user_id.id for inter_invoice in self.sudo(intercompany_uid).search( [('auto_invoice_id', '=', invoice.id)]): inter_invoice.signal_workflow('invoice_cancel') - return super(account_invoice, self).action_cancel() + return super(AccountInvoice, self).action_cancel() diff --git a/inter_company_rules/models/purchase_order.py b/inter_company_rules/models/purchase_order.py index 36253ecd436..0426512b14d 100644 --- a/inter_company_rules/models/purchase_order.py +++ b/inter_company_rules/models/purchase_order.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from openerp import api, fields, models, _ -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError -class purchase_order(models.Model): +class PurchaseOrder(models.Model): _inherit = "purchase.order" @@ -16,7 +16,7 @@ class purchase_order(models.Model): @api.multi def wkf_confirm_order(self): """ Generate inter company sale order base on conditions.""" - res = super(purchase_order, self).wkf_confirm_order() + res = super(PurchaseOrder, self).wkf_confirm_order() for order in self: # get the company from partner then trigger action of # intercompany relation @@ -38,26 +38,30 @@ def inter_company_create_sale_order(self, company): :rtype company : res.company record """ SaleOrder = self.env['sale.order'] - company_partner = self.company_id.partner_id # find user for creating and validation SO/PO from partner company intercompany_uid = (company.intercompany_user_id and company.intercompany_user_id.id or False) if not intercompany_uid: - raise Warning(_( + raise UserError(_( 'Provide at least one user for inter company relation for % ') % company.name) # check intercompany user access rights if not SaleOrder.sudo(intercompany_uid).check_access_rights( 'create', raise_exception=False): - raise Warning(_( + raise UserError(_( "Inter company user of company %s doesn't have enough " "access rights") % company.name) + # Accessing to selling partner with selling user, so data like + # property_account_position can be retrieved + company_partner = self.env['res.partner'].sudo( + intercompany_uid).browse(self.company_id.partner_id.id) + # check pricelist currency should be same with SO/PO document if self.pricelist_id.currency_id.id != ( company_partner.property_product_pricelist.currency_id.id): - raise Warning(_( + raise UserError(_( 'You cannot create SO from PO because ' 'sale price list currency is different than ' 'purchase price list currency.')) @@ -102,8 +106,10 @@ def _prepare_sale_order_data(self, name, partner, company, 'delivery', 'contact']) return { - 'name': (self.env['ir.sequence'].sudo().next_by_code('sale.order') - or '/'), + 'name': ( + self.env['ir.sequence'].sudo().next_by_code('sale.order') or + '/' + ), 'company_id': company.id, 'client_order_ref': name, 'partner_id': partner.id, @@ -131,20 +137,24 @@ def _prepare_sale_order_line_data(self, line, company, sale_id): # it may not affected because of parallel company relation price = line.price_unit or 0.0 taxes = line.taxes_id + product = None if line.product_id: - taxes = line.product_id.taxes_id + # make a new browse otherwise line._uid keeps the purchasing + # company's user and can't see the selling company's taxes + product = self.env['product.product'].browse(line.product_id.id) + taxes = product.taxes_id company_taxes = [tax_rec.id for tax_rec in taxes if tax_rec.company_id.id == company.id] return { - 'name': line.product_id and line.product_id.name or line.name, + 'name': line.name, 'order_id': sale_id, 'product_uom_qty': line.product_qty, - 'product_id': line.product_id and line.product_id.id or False, - 'product_uom': (line.product_id and line.product_id.uom_id.id or + 'product_id': product and product.id or False, + 'product_uom': (product and product.uom_id.id or line.product_uom.id), 'price_unit': price, - 'delay': line.product_id and line.product_id.sale_delay or 0.0, + 'delay': product and product.sale_delay or 0.0, 'company_id': company.id, 'tax_id': [(6, 0, company_taxes)], } diff --git a/inter_company_rules/models/res_company.py b/inter_company_rules/models/res_company.py index b5059c1ab05..006184e9736 100644 --- a/inter_company_rules/models/res_company.py +++ b/inter_company_rules/models/res_company.py @@ -3,7 +3,7 @@ from openerp.exceptions import ValidationError -class res_company(models.Model): +class ResCompany(models.Model): _inherit = 'res.company' diff --git a/inter_company_rules/models/res_config.py b/inter_company_rules/models/res_config.py index 0d4de9349d2..d15291579b7 100644 --- a/inter_company_rules/models/res_config.py +++ b/inter_company_rules/models/res_config.py @@ -2,7 +2,7 @@ from openerp import models, fields, api -class inter_company_rules_configuration(models.TransientModel): +class InterCompanyRulesConfig(models.TransientModel): _inherit = 'base.config.settings' diff --git a/inter_company_rules/models/sale_order.py b/inter_company_rules/models/sale_order.py index eb8232361b5..e6bd8452884 100644 --- a/inter_company_rules/models/sale_order.py +++ b/inter_company_rules/models/sale_order.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- from openerp import api, fields, models, _ -from openerp.exceptions import Warning +from openerp.exceptions import Warning as UserError -class sale_order(models.Model): +class SaleOrder(models.Model): _inherit = "sale.order" @@ -16,7 +16,7 @@ class sale_order(models.Model): @api.multi def action_button_confirm(self): """ Generate inter company purchase order based on conditions """ - res = super(sale_order, self).action_button_confirm() + res = super(SaleOrder, self).action_button_confirm() for order in self: # if company_id not found, return to normal behavior if not order.company_id: @@ -48,13 +48,13 @@ def inter_company_create_purchase_order(self, company): intercompany_uid = (company.intercompany_user_id and company.intercompany_user_id.id or False) if not intercompany_uid: - raise Warning(_( + raise UserError(_( 'Provide one user for intercompany relation for % ') % company.name) # check intercompany user access rights if not PurchaseOrder.sudo(intercompany_uid).check_access_rights( 'create', raise_exception=False): - raise Warning(_( + raise UserError(_( "Inter company user of company %s doesn't have enough " "access rights") % company.name) @@ -62,7 +62,7 @@ def inter_company_create_purchase_order(self, company): if self.pricelist_id.currency_id.id != ( company_partner.property_product_pricelist_purchase. currency_id.id): - raise Warning(_( + raise UserError(_( 'You cannot create PO from SO because ' 'purchase pricelist currency is different than ' 'sale pricelist currency.')) @@ -103,7 +103,7 @@ def _prepare_purchase_order_data(self, company, company_partner): company.warehouse_id.company_id.id == company.id and company.warehouse_id or False) if not warehouse: - raise Warning(_( + raise UserError(_( 'Configure correct warehouse for company(%s) from ' 'Menu: Settings/companies/companies' % (company.name))) diff --git a/inter_company_rules/test/inter_company_invoice.yml b/inter_company_rules/test/inter_company_invoice.yml index b299e3fa145..e925b74ea91 100644 --- a/inter_company_rules/test/inter_company_invoice.yml +++ b/inter_company_rules/test/inter_company_invoice.yml @@ -73,6 +73,7 @@ assert supplier_invoice.invoice_line[0].account_id.company_id.id == ref("company_b"), "Applied account in created invoice line is not relevant to company." assert supplier_invoice.state == "draft", "invoice should be in draft state." - assert supplier_invoice.amount_total == 450.0, "Total amount is incorrect." + # invoice total must include tax (in configurable CoA is 15%) + assert supplier_invoice.amount_total == 517.5, "Total amount is incorrect. Found %s" % supplier_invoice.amount_total assert supplier_invoice.company_id.id == ref("company_b"), "Applied company in created invoice is incorrect." assert supplier_invoice.account_id.company_id.id == ref("company_b"), "Applied account in created invoice is not relevant to company." diff --git a/inter_company_rules/test/test_intercompany_data.yml b/inter_company_rules/test/test_intercompany_data.yml index a98f819e6bb..3753bcfc942 100644 --- a/inter_company_rules/test/test_intercompany_data.yml +++ b/inter_company_rules/test/test_intercompany_data.yml @@ -100,6 +100,12 @@ groups_id: - base.group_sale_salesman - purchase.group_purchase_user +- + !record {model: res.company, id: company_a, view: False}: + intercompany_user_id: res_users_company_a +- + !record {model: res.company, id: company_b, view: False}: + intercompany_user_id: res_users_company_b - Install COA for new companies. - diff --git a/inter_company_rules/views/inter_company_so_po_view.xml b/inter_company_rules/views/inter_company_so_po_view.xml index 1f94d71bd18..f1d7bde1841 100644 --- a/inter_company_rules/views/inter_company_so_po_view.xml +++ b/inter_company_rules/views/inter_company_so_po_view.xml @@ -20,5 +20,5 @@ - + diff --git a/inter_company_rules/views/res_config_view.xml b/inter_company_rules/views/res_config_view.xml index 9a63622a683..73dafb92059 100644 --- a/inter_company_rules/views/res_config_view.xml +++ b/inter_company_rules/views/res_config_view.xml @@ -31,4 +31,4 @@ - \ No newline at end of file +