diff --git a/addons/base_branch_company/models/__init__.py b/addons/base_branch_company/models/__init__.py index ee7e30da..fdc1be02 100644 --- a/addons/base_branch_company/models/__init__.py +++ b/addons/base_branch_company/models/__init__.py @@ -5,4 +5,3 @@ from . import res_branch from . import ir_branch_company from . import res_partner - diff --git a/addons/base_branch_company/models/res_branch.py b/addons/base_branch_company/models/res_branch.py index 943bd50d..bba8082b 100644 --- a/addons/base_branch_company/models/res_branch.py +++ b/addons/base_branch_company/models/res_branch.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from flectra import api, fields, models +# from flectra.exceptions import ValidationError class Company(models.Model): @@ -22,6 +23,7 @@ class Company(models.Model): 'company_id': company.id}) return company + class ResBranch(models.Model): _name = "res.branch" @@ -45,7 +47,8 @@ class ResBranch(models.Model): phone = fields.Char() mobile = fields.Char() - _sql_constraints = [('branch_code_company_uniq', 'unique (code,company_id)', + _sql_constraints = [('branch_code_company_uniq', + 'unique (code,company_id)', 'The branch code must be unique per company!')] @api.model @@ -109,13 +112,23 @@ class Users(models.Model): default=_get_branch, domain="[('company_id','=',company_id)" "]") - branches_count = fields.Integer(compute='_compute_branches_count', - string="Number of Companies", - default=_branches_count) + branches_count = fields.Integer( + compute='_compute_branches_count', + string="Number of Companies", default=_branches_count) + + # To do : Check with all base module test cases + # @api.multi + # @api.constrains('default_branch_id', 'branch_ids') + # def _check_branches(self): + # for user in self: + # if user.branch_ids \ + # and user.default_branch_id not in user.branch_ids: + # raise ValidationError(_('The selected Default Branch (%s) ' + # 'is not in the Branches!') % ( + # user.default_branch_id.name)) @api.multi def _compute_branches_count(self): branches_count = self._branches_count() for user in self: user.branches_count = branches_count - diff --git a/addons/base_branch_company/models/res_partner.py b/addons/base_branch_company/models/res_partner.py index 932be8c8..02a3eed6 100644 --- a/addons/base_branch_company/models/res_partner.py +++ b/addons/base_branch_company/models/res_partner.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -from flectra import api, fields, models +from flectra import api, models + class Partner(models.Model): _name = "res.partner" @@ -17,6 +18,3 @@ class Partner(models.Model): self.branch_id.with_context(ctx).write(branch_vals) result = super(Partner, self).write(vals) return result - - - diff --git a/addons/base_branch_company/tests/test_branch.py b/addons/base_branch_company/tests/test_branch.py index 5677d353..bfa19803 100644 --- a/addons/base_branch_company/tests/test_branch.py +++ b/addons/base_branch_company/tests/test_branch.py @@ -5,6 +5,7 @@ from flectra.tests.common import TransactionCase import logging _logger = logging.getLogger(__name__) + class TestMultiBranch(TransactionCase): def setUp(self): super(TestMultiBranch, self).setUp() @@ -14,10 +15,11 @@ class TestMultiBranch(TransactionCase): self.branch0 = self.env.ref('base_branch_company.data_branch_1') self.branch1 = self.env.ref('base_branch_company.data_branch_2') - self.user_1 = self.create_user(self.main_company, 'user_1', self.branch0, - [self.branch0, self.branch1]) - self.user_2 = self.create_user(self.main_company, 'user_2', self.branch1, - [self.branch1]) + self.user_1 = self.create_user( + self.main_company, 'user_1', self.branch0, + [self.branch0, self.branch1]) + self.user_2 = self.create_user( + self.main_company, 'user_2', self.branch1, [self.branch1]) self.model_id = \ self.env['ir.model'].search([('model', '=', 'res.partner')]) @@ -45,7 +47,7 @@ class TestMultiBranch(TransactionCase): def create_user(self, main_company, user_name, branch_id, branch_ids): data = { 'company_ids': [(4, main_company.id)], - 'branch_ids': [(4, branch_id.id) for branch_id in branch_ids], + 'branch_ids': [(4, branch.id) for branch in branch_ids], 'company_id': main_company.id, 'default_branch_id': branch_id.id, 'login': user_name, @@ -57,24 +59,17 @@ class TestMultiBranch(TransactionCase): user_obj = self.env['res.users'].create(data) return user_obj - def test_user_authentication(self): partner = self.partner_obj.sudo(self.user_1.id).search( [('id', '=', self.branch_partner1.id), ('branch_id', '=', self.branch0.id)]) - self.assertNotEqual(partner.ids, [], 'Test User have access to ' - 'Branch %s' % self.branch0.name) + self.assertNotEqual(partner.ids, [], + 'Test User have access to Branch %s' % + self.branch0.name) partner = self.partner_obj.sudo(self.user_2.id).search( [('id', '=', self.branch_partner0.id), ('branch_id', '=', self.branch0.id)]) self.assertEqual(partner.ids, [], - 'Test User should not have access to ' - 'Branch %s' % self.branch0.name) - - - - - - - + 'Test User should not have access to Branch %s' % + self.branch0.name) diff --git a/addons/base_branch_company/views/res_branch_view.xml b/addons/base_branch_company/views/res_branch_view.xml index 3e2b8078..408db74d 100644 --- a/addons/base_branch_company/views/res_branch_view.xml +++ b/addons/base_branch_company/views/res_branch_view.xml @@ -90,7 +90,7 @@ - + diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 911ce11f..90391122 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -70,7 +70,11 @@ class PurchaseOrder(models.Model): def _default_picking_type(self): type_obj = self.env['stock.picking.type'] company_id = self.env.context.get('company_id') or self.env.user.company_id.id - types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)]) + branch_id = self.env.context.get( + 'branch_id') or self.env.user.default_branch_id.id + types = type_obj.search([('code', '=', 'incoming'), + ('warehouse_id.company_id', '=', company_id), + ('warehouse_id.branch_id', '=', branch_id)]) if not types: types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)]) return types[:1] diff --git a/addons/purchase_indent/demo/puchase_indent_demo.xml b/addons/purchase_indent/demo/puchase_indent_demo.xml index f96358d4..7879b8d7 100644 --- a/addons/purchase_indent/demo/puchase_indent_demo.xml +++ b/addons/purchase_indent/demo/puchase_indent_demo.xml @@ -15,6 +15,7 @@ 2 2.0 + + + + + Purchase Indent Line multi-branch + + + + ['|', ('branch_id', '=', False), '|', ('branch_id', '=', user.default_branch_id.id), + ('branch_id', 'in', user.branch_ids.ids)] + + + diff --git a/addons/purchase_indent/tests/test_purchase_indent.py b/addons/purchase_indent/tests/test_purchase_indent.py index 67329bca..6bb5281b 100644 --- a/addons/purchase_indent/tests/test_purchase_indent.py +++ b/addons/purchase_indent/tests/test_purchase_indent.py @@ -2,11 +2,9 @@ import logging from datetime import datetime - from flectra.exceptions import Warning from flectra.tests.common import TransactionCase from flectra.tools.misc import formatLang - from flectra import _ @@ -17,22 +15,30 @@ class TestPurchaseIndent(TransactionCase): self.PurchaseIndent = self.env['purchase.indent'] self.PurchaseIndentLine = self.env['purchase.indent.line'] self.Requisition_Req = self.env['wiz.requisition.request'] - - def test_00_purchase_indent_flow(self): + self.company_id = self.env.ref('base.main_company') + self.branch_id = self.env.ref('base_branch_company.data_branch_2') self.partner_id = self.env.ref('base.res_partner_address_12') self.category_id = self.env.ref('product.product_category_5') self.product_id_1 = self.env.ref('product.product_product_24') self.product_id_2 = self.env.ref('product.product_product_16') self.product_id_3 = self.env.ref('product.consu_delivery_03') - self.company_id = self.env.ref('base.main_company') self.agreement_type_id = \ self.env.ref('purchase_requisition.type_multi') - purchase_indent_vals_1 = { + purchase_indent_vals = { 'company_id': self.company_id.id, 'category_id': self.category_id.id, 'request_date': datetime.today(), 'user_id': self.env.user.id, + 'branch_id': self.branch_id.id + } + + self.purchase_indent_id = \ + self.PurchaseIndent.create(purchase_indent_vals) + self.purchase_indent_id_1 = self.purchase_indent_id.copy() + + def test_00_purchase_indent_flow(self): + self.purchase_indent_id.write({ 'indent_line': [ (0, 0, { 'name': self.product_id_1.name, @@ -46,13 +52,9 @@ class TestPurchaseIndent(TransactionCase): 'product_qty': 15.0, 'product_uom': self.product_id_2.uom_po_id.id, })], - } + }) - purchase_indent_vals_2 = { - 'company_id': self.company_id.id, - 'category_id': self.category_id.id, - 'request_date': datetime.today(), - 'user_id': self.env.user.id, + self.purchase_indent_id_1.write({ 'indent_line': [ (0, 0, { 'name': self.product_id_3.name, @@ -72,31 +74,32 @@ class TestPurchaseIndent(TransactionCase): 'product_qty': 5.0, 'product_uom': self.product_id_2.uom_po_id.id, })], - } - self.pi = self.PurchaseIndent.create(purchase_indent_vals_1) - self.pi_1 = self.PurchaseIndent.create(purchase_indent_vals_2) - self.assertTrue( - self.pi, 'Purchase Indent: no purchase indent created') - self.assertTrue( - self.pi_1, 'Purchase Indent: no purchase indent created') + }) - for line in self.pi.indent_line: + self.assertTrue( + self.purchase_indent_id, + 'Purchase Indent: no purchase indent created') + self.assertTrue( + self.purchase_indent_id_1, + 'Purchase Indent: no purchase indent created') + + for line in self.purchase_indent_id.indent_line: if line.product_qty < 0: raise Warning(_("Quantity (%s) can not be Negative!") % ( formatLang(self.env, line.product_qty, digits=2))) - for line in self.pi_1.indent_line: + for line in self.purchase_indent_id_1.indent_line: if line.product_qty < 0: raise Warning(_("Quantity (%s) can not be Negative!") % ( formatLang(self.env, line.product_qty, digits=2))) - self.pi.action_confirm() - self.pi_1.action_confirm() + self.purchase_indent_id.action_confirm() + self.purchase_indent_id_1.action_confirm() requisition_id = self.Requisition_Req.create({ 'category_id': self.category_id.id, 'order_type': 'po', - 'purchase_indent_id': self.pi.id, + 'purchase_indent_id': self.purchase_indent_id.id, }) requisition_id.onchange_purchase_indent_id() requisition_id.dummy_wiz_indent_line[0].write({'requisition_qty': 5}) @@ -106,10 +109,15 @@ class TestPurchaseIndent(TransactionCase): for line in requisition_id.wiz_indent_line: line.write({'price_unit': 100}) requisition_id.action_create() + logging.info('Successful: Purchase Order Created!') + + # Cancel Purchase Order + self.purchase_indent_id.indent_history_ids[0].order_id.button_cancel() + requisition_id_1 = self.Requisition_Req.create({ 'category_id': self.category_id.id, 'order_type': 'pa', - 'purchase_indent_id': self.pi_1.id, + 'purchase_indent_id': self.purchase_indent_id_1.id, 'requisition_type_id': self.agreement_type_id.id, }) @@ -120,4 +128,4 @@ class TestPurchaseIndent(TransactionCase): for line in requisition_id_1.wiz_indent_line: line.write({'price_unit': 100}) requisition_id_1.action_create() - logging.info('\n\nSuccessful: Purchase Agreement Created!') + logging.info('Successful: Purchase Agreement Created!') diff --git a/addons/purchase_indent/views/purchase_indent_view.xml b/addons/purchase_indent/views/purchase_indent_view.xml index 37fc086b..d2dbec57 100644 --- a/addons/purchase_indent/views/purchase_indent_view.xml +++ b/addons/purchase_indent/views/purchase_indent_view.xml @@ -21,8 +21,14 @@ purchase.requisition + +