From 462167e087d6c27e0e524b9f49ede1909ec5d112 Mon Sep 17 00:00:00 2001 From: kunjal patel Date: Mon, 12 Feb 2018 11:43:43 +0000 Subject: [PATCH] [IMP]: Feature: New Branch Configuration and Setup --- addons/account/models/account_payment.py | 29 ++++++-- addons/account/tests/test_payment_branch.py | 19 +++-- addons/account/views/account_payment_view.xml | 3 + addons/account/views/account_view.xml | 3 + addons/base_branch_company/__init__.py | 1 + addons/base_branch_company/__manifest__.py | 2 + .../views/res_branch_config_view.xml | 32 +++++++++ addons/base_branch_company/wizard/__init__.py | 4 ++ .../wizard/branch_config.py | 71 +++++++++++++++++++ .../wizard/branch_config_view.xml | 59 +++++++++++++++ addons/sales_team/views/crm_team_views.xml | 1 + 11 files changed, 213 insertions(+), 11 deletions(-) create mode 100644 addons/base_branch_company/views/res_branch_config_view.xml create mode 100644 addons/base_branch_company/wizard/__init__.py create mode 100644 addons/base_branch_company/wizard/branch_config.py create mode 100644 addons/base_branch_company/wizard/branch_config_view.xml diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py index 73ed3d4a..989ee375 100644 --- a/addons/account/models/account_payment.py +++ b/addons/account/models/account_payment.py @@ -102,7 +102,7 @@ class account_abstract_payment(models.AbstractModel): class account_register_payments(models.TransientModel): _name = "account.register.payments" - _inherit = 'account.abstract.payment' + _inherit = ['account.abstract.payment'] _description = "Register payments on multiple invoices" invoice_ids = fields.Many2many('account.invoice', string='Invoices', copy=False) @@ -240,7 +240,7 @@ class account_register_payments(models.TransientModel): class account_payment(models.Model): _name = "account.payment" - _inherit = ['mail.thread', 'account.abstract.payment', 'ir.branch.company.mixin'] + _inherit = ['mail.thread', 'account.abstract.payment'] _description = "Payments" _order = "payment_date desc, name desc" @@ -269,6 +269,15 @@ class account_payment(models.Model): else: self.payment_difference = self._compute_total_invoices_amount() - self.amount + + @api.depends('journal_id') + def _compute_branch(self): + for payment in self: + if payment.journal_id: + payment.branch_id = \ + payment.journal_id.branch_id + + company_id = fields.Many2one(store=True) name = fields.Char(readonly=True, copy=False, default="Draft Payment") # The name is attributed upon post() state = fields.Selection([('draft', 'Draft'), ('posted', 'Posted'), ('sent', 'Sent'), ('reconciled', 'Reconciled'), ('cancelled', 'Cancelled')], readonly=True, default='draft', copy=False, string="Status") @@ -297,6 +306,8 @@ class account_payment(models.Model): # FIXME: ondelete='restrict' not working (eg. cancel a bank statement reconciliation with a payment) move_line_ids = fields.One2many('account.move.line', 'payment_id', readonly=True, copy=False, ondelete='restrict') move_reconciled = fields.Boolean(compute="_get_move_reconciled", readonly=True) + branch_id = fields.Many2one('res.branch', 'Branch', + compute='_compute_branch', readonly=True, store=True) def open_payment_matching_screen(self): # Open reconciliation view for customers/suppliers @@ -461,7 +472,6 @@ class account_payment(models.Model): If the payment is a transfer, a second journal entry is created in the destination journal to receive money from the transfer account. """ for rec in self: - if rec.state != 'draft': raise UserError(_("Only a draft payment can be posted.")) @@ -524,9 +534,7 @@ class account_payment(models.Model): #if all the invoices selected share the same currency, record the paiement in that currency too invoice_currency = self.invoice_ids[0].currency_id debit, credit, amount_currency, currency_id = aml_obj.with_context(date=self.payment_date).compute_amount_fields(amount, self.currency_id, self.company_id.currency_id, invoice_currency) - move = self.env['account.move'].create(self._get_move_vals()) - #Write line corresponding to invoice payment counterpart_aml_dict = self._get_shared_move_line_vals(debit, credit, amount_currency, move.id, False) counterpart_aml_dict.update(self._get_counterpart_move_line_vals(self.invoice_ids)) @@ -598,6 +606,7 @@ class account_payment(models.Model): dst_liquidity_aml_dict.update({ 'name': _('Transfer from %s') % self.journal_id.name, 'account_id': self.destination_journal_id.default_credit_account_id.id, + 'branch_id': self.destination_journal_id.branch_id.id or False, 'currency_id': self.destination_journal_id.currency_id.id, 'journal_id': self.destination_journal_id.id}) aml_obj.create(dst_liquidity_aml_dict) @@ -606,6 +615,7 @@ class account_payment(models.Model): transfer_debit_aml_dict.update({ 'name': self.name, 'account_id': self.company_id.transfer_account_id.id, + 'branch_id': self.journal_id.branch_id.id or False, 'journal_id': self.destination_journal_id.id}) if self.currency_id != self.company_id.currency_id: transfer_debit_aml_dict.update({ @@ -666,10 +676,15 @@ class account_payment(models.Model): for inv in invoice: if inv.move_id: name += inv.number + ', ' - name = name[:len(name)-2] + name = name[:len(name)-2] + if len(invoice) == 1: + branch_id = invoice.branch_id.id or False + else: + branch_id = self.branch_id.id or False return { 'name': name, 'account_id': self.destination_account_id.id, + 'branch_id': branch_id, 'journal_id': self.journal_id.id, 'currency_id': self.currency_id != self.company_id.currency_id and self.currency_id.id or False, } @@ -693,5 +708,5 @@ class account_payment(models.Model): 'amount_currency': amount_currency, 'currency_id': self.journal_id.currency_id.id, }) - + vals['branch_id'] = self.journal_id.branch_id.id or False return vals diff --git a/addons/account/tests/test_payment_branch.py b/addons/account/tests/test_payment_branch.py index 9135bae7..61075272 100644 --- a/addons/account/tests/test_payment_branch.py +++ b/addons/account/tests/test_payment_branch.py @@ -7,15 +7,26 @@ class TestPaymentsBranch(test_account_branch.TestAccountBranch): def test_payment_branch(self): self.invoice_id = self.model_account_invoice.sudo(self.user_id.id).create( - self.invoice_values(self.branch_2.id)) + self.invoice_values(self.branch_1.id)) self.invoice_id.sudo(self.user_id.id).action_invoice_open() - + self.journal_model = self.env['account.journal'] + self.account_model = self.env['account.account'] + self.company = self.env.ref('base.main_company') + user_type = self.env.ref('account.data_account_type_liquidity') + self.cash1_account_id = self.account_model.create( + {'name': 'Cash 1 - Test', 'code': 'test_cash_1', + 'user_type_id': user_type.id, 'company_id': self.company.id, }) + self.cash_journal_1 = self.journal_model.create( + {'name': 'Cash Journal 1 - Test', 'code': 'test_cash_1', + 'type': 'cash', 'company_id': self.company.id, + 'default_debit_account_id': self.cash1_account_id.id, + 'default_credit_account_id': self.cash1_account_id.id, + 'branch_id': self.branch_1.id}) context = {'active_ids': [self.invoice_id.id], 'active_model': 'account.invoice'} create_payments = self.env['account.register.payments'].sudo(self.user_id.id).with_context(context).create({ 'payment_method_id': self.env.ref("account.account_payment_method_manual_in").id, - 'journal_id': self.cash_journal.id, + 'journal_id': self.cash_journal_1.id, 'payment_date': time.strftime('%Y') + '-12-17', - }) create_payments.create_payments() payment = self.env['account.payment'].sudo(self.user_2.id).search([('branch_id', '=', self.branch_2.id)]) diff --git a/addons/account/views/account_payment_view.xml b/addons/account/views/account_payment_view.xml index 62950e1f..fc34fcc0 100644 --- a/addons/account/views/account_payment_view.xml +++ b/addons/account/views/account_payment_view.xml @@ -10,6 +10,7 @@ + @@ -29,6 +30,7 @@ + @@ -152,6 +154,7 @@ + diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index 9142f939..05769027 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -284,6 +284,9 @@ + diff --git a/addons/base_branch_company/__init__.py b/addons/base_branch_company/__init__.py index 6a64595a..66aecd2c 100644 --- a/addons/base_branch_company/__init__.py +++ b/addons/base_branch_company/__init__.py @@ -2,3 +2,4 @@ # Part of flectra. See LICENSE file for full copyright and licensing details. from . import models +from . import wizard diff --git a/addons/base_branch_company/__manifest__.py b/addons/base_branch_company/__manifest__.py index 4e4ba66e..167d92e6 100644 --- a/addons/base_branch_company/__manifest__.py +++ b/addons/base_branch_company/__manifest__.py @@ -24,9 +24,11 @@ Main Features 'depends': ['base'], 'data': [ 'demo/branch_data.xml', + 'wizard/branch_config_view.xml', 'security/branch_security.xml', 'security/ir.model.access.csv', 'views/res_branch_view.xml', + 'views/res_branch_config_view.xml', ], 'demo': [ 'demo/branch_demo.xml', diff --git a/addons/base_branch_company/views/res_branch_config_view.xml b/addons/base_branch_company/views/res_branch_config_view.xml new file mode 100644 index 00000000..87b422f7 --- /dev/null +++ b/addons/base_branch_company/views/res_branch_config_view.xml @@ -0,0 +1,32 @@ + + + + res.config.settings.view.form.inherit.base.setup + res.config.settings + + + + +
+

Multi-Branch

+
+
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/addons/base_branch_company/wizard/__init__.py b/addons/base_branch_company/wizard/__init__.py new file mode 100644 index 00000000..8de7c2ed --- /dev/null +++ b/addons/base_branch_company/wizard/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. + +from . import branch_config diff --git a/addons/base_branch_company/wizard/branch_config.py b/addons/base_branch_company/wizard/branch_config.py new file mode 100644 index 00000000..490cb971 --- /dev/null +++ b/addons/base_branch_company/wizard/branch_config.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- +# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details. + +from flectra import api, models, fields + + +class BarnchConfiguration(models.TransientModel): + _name = 'branch.config' + + name = fields.Char(string='Name', required=True) + code = fields.Char(string='Code', required=True) + branch_id = fields.Many2one('res.branch', 'Branch') + company_id = fields.Many2one('res.company', string="Company", + default=lambda self: self.env.user.company_id, required=True) + partner_id = fields.Many2one('res.partner', string='Partner') + street = fields.Char() + street2 = fields.Char() + zip = fields.Char(change_default=True) + city = fields.Char() + state_id = fields.Many2one("res.country.state", string='State', + ondelete='restrict') + country_id = fields.Many2one('res.country', string='Country', + ondelete='restrict') + email = fields.Char() + phone = fields.Char() + mobile = fields.Char() + state = fields.Selection([('draft', 'Draft'), ('confirm', 'Confirm')], + default='draft') + user_ids = fields.Many2many('res.users', 'res_users_branch_rel', + 'user_id', 'branch_id', 'Allowed Branch for users', + domain="[('company_id','=',company_id)]") + default_user_ids = fields.Many2many('res.users', 'res_users_branch_default_rel', + 'user_id', 'branch_id', 'Default Branch for users', + domain="[('company_id','=',company_id)]") + + @api.multi + def branch_config(self): + s_ids = self.search_read([('id', '=', self.id)], [])[0] + branch = self.env['res.branch'].create({ + 'name': s_ids['name'], + 'code': s_ids['code'], + 'street': s_ids['street'], + 'street2': s_ids['street2'], + 'zip': s_ids['zip'], + 'city': s_ids['city'], + 'state_id': s_ids['state_id'] and s_ids['state_id'][0], + 'country_id': s_ids['country_id'] and s_ids['country_id'][0], + 'email': s_ids['email'], + 'phone': s_ids['phone'], + 'company_id': s_ids['company_id'] and s_ids['company_id'][0], + 'mobile': s_ids['mobile'], + }) + self.write({'state': 'confirm', + 'partner_id': branch.partner_id.id, + 'branch_id': branch.id}) + view_id = self.env.ref( + 'base_branch_company.view_branch_config') + context = dict(self._context) + return {'views': [(view_id.id, 'form')], 'view_id': view_id.id, + 'type': 'ir.actions.act_window', 'view_type': 'form', + 'view_mode': 'form', 'res_model': 'branch.config', + 'target': 'new', 'res_id': self.id, 'context': context, } + + + @api.multi + def finish_branch_config(self): + for user_id in self.user_ids: + user_id.write({'branch_ids': [(4, self.branch_id.id)]}) + for user_id in self.user_ids: + user_id.write({'default_branch_id': self.branch_id.id}) + diff --git a/addons/base_branch_company/wizard/branch_config_view.xml b/addons/base_branch_company/wizard/branch_config_view.xml new file mode 100644 index 00000000..1e870ce3 --- /dev/null +++ b/addons/base_branch_company/wizard/branch_config_view.xml @@ -0,0 +1,59 @@ + + + + Branch Configuration + branch.config + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + Branch Configuration + ir.actions.act_window + branch.config + form + form + new + + +
diff --git a/addons/sales_team/views/crm_team_views.xml b/addons/sales_team/views/crm_team_views.xml index 446cb0c6..b83142a9 100644 --- a/addons/sales_team/views/crm_team_views.xml +++ b/addons/sales_team/views/crm_team_views.xml @@ -63,6 +63,7 @@ +