[IMP]: Feature: New Branch Configuration and Setup
This commit is contained in:
parent
09dd9328d8
commit
462167e087
@ -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
|
||||
|
@ -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)])
|
||||
|
@ -10,6 +10,7 @@
|
||||
<field name="payment_date"/>
|
||||
<field name="name"/>
|
||||
<field name="journal_id"/>
|
||||
<field name="branch_id" groups="base_branch_company.group_multi_branch"/>
|
||||
<field name="payment_method_id"/>
|
||||
<field name="partner_id" string="Customer"/>
|
||||
<field name="amount" sum="Amount"/>
|
||||
@ -29,6 +30,7 @@
|
||||
<field name="payment_date"/>
|
||||
<field name="name"/>
|
||||
<field name="journal_id"/>
|
||||
<field name="branch_id" groups="base_branch_company.group_multi_branch"/>
|
||||
<field name="payment_method_id"/>
|
||||
<field name="partner_id" string="Vendor"/>
|
||||
<field name="amount" sum="Amount"/>
|
||||
@ -152,6 +154,7 @@
|
||||
<field name="currency_id" options="{'no_create': True, 'no_open': True}" groups="base.group_multi_currency" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
|
||||
</div>
|
||||
<field name="journal_id" widget="selection" attrs="{'readonly': [('state', '!=', 'draft')]}"/>
|
||||
<field name="branch_id" groups="base_branch_company.group_multi_branch"/>
|
||||
<field name="destination_journal_id" widget="selection" attrs="{'required': [('payment_type', '=', 'transfer')], 'invisible': [('payment_type', '!=', 'transfer')], 'readonly': [('state', '!=', 'draft')]}"/>
|
||||
<field name="hide_payment_method" invisible="1"/>
|
||||
<field name="payment_method_id" string=" " widget="radio" attrs="{'invisible': [('hide_payment_method', '=', True)], 'readonly': [('state', '!=', 'draft')]}"/>
|
||||
|
@ -284,6 +284,9 @@
|
||||
</group>
|
||||
<group>
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
<field name="branch_id" options="{'no_create': True}"
|
||||
groups="base_branch_company.group_multi_branch"
|
||||
attrs="{'invisible':[('type','not in', ['bank', 'cash'])]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
|
@ -2,3 +2,4 @@
|
||||
# Part of flectra. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
@ -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',
|
||||
|
32
addons/base_branch_company/views/res_branch_config_view.xml
Normal file
32
addons/base_branch_company/views/res_branch_config_view.xml
Normal file
@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<flectra>
|
||||
<record id="res_config_settings_view_form" model="ir.ui.view">
|
||||
<field name="name">res.config.settings.view.form.inherit.base.setup</field>
|
||||
<field name="model">res.config.settings</field>
|
||||
<field name="priority" eval="100"/>
|
||||
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[hasclass('settings')]" position="inside">
|
||||
<div class="app_settings_block">
|
||||
<h2>Multi-Branch</h2>
|
||||
<div class="row mt16 o_settings_container" id="emails">
|
||||
<div class="col-xs-12 col-md-6 o_setting_box">
|
||||
<div class="o_setting_left_pane"/>
|
||||
<div class="o_setting_right_pane">
|
||||
<label string="Branches"/>
|
||||
<div class="text-muted">
|
||||
Configure your Branch
|
||||
</div>
|
||||
<div class="content-group">
|
||||
<div class="mt16">
|
||||
<button name="%(action_view_branch_config)d" string="Branch Configuration" type="action" class="oe_link" groups="base.group_no_one" icon="fa-arrow-right"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</flectra>
|
4
addons/base_branch_company/wizard/__init__.py
Normal file
4
addons/base_branch_company/wizard/__init__.py
Normal file
@ -0,0 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import branch_config
|
71
addons/base_branch_company/wizard/branch_config.py
Normal file
71
addons/base_branch_company/wizard/branch_config.py
Normal file
@ -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})
|
||||
|
59
addons/base_branch_company/wizard/branch_config_view.xml
Normal file
59
addons/base_branch_company/wizard/branch_config_view.xml
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<flectra>
|
||||
<record id="view_branch_config" model="ir.ui.view">
|
||||
<field name="name">Branch Configuration</field>
|
||||
<field name="model">branch.config</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Branch Configuration">
|
||||
<group col="4" attrs="{'invisible': [('state', '!=', 'draft')]}">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="state" invisible="1"/>
|
||||
</group>
|
||||
<group attrs="{'invisible': [('state', '=', 'draft')]}">
|
||||
<field name="branch_id" readonly="1"/>
|
||||
<!--<field name="partner_id" invisible="1"/>-->
|
||||
</group>
|
||||
<group col="4" attrs="{'invisible': [('state', '=', 'draft')]}">
|
||||
<field name="user_ids" widget="many2many_tags"/>
|
||||
<field name="default_user_ids" widget="many2many_tags"/>
|
||||
</group>
|
||||
<group attrs="{'invisible': [('state', '!=', 'draft')]}">
|
||||
<group>
|
||||
<label for="street" string="Address"/>
|
||||
<div class="o_address_format">
|
||||
<field name="street" placeholder="Street..." class="o_address_street"/>
|
||||
<field name="street2" placeholder="Street 2..." class="o_address_street"/>
|
||||
<field name="city" placeholder="City" class="o_address_city"/>
|
||||
<field name="state_id" class="o_address_state" placeholder="State" options='{"no_open": True}'
|
||||
context="{'country_id': country_id, 'zip': zip}"/>
|
||||
<field name="zip" placeholder="ZIP" class="o_address_zip"/>
|
||||
<field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/>
|
||||
</div>
|
||||
</group>
|
||||
<group>
|
||||
<field name="phone" widget="phone"/>
|
||||
<field name="mobile" widget="phone"/>
|
||||
<field name="email" widget="email" context="{'gravatar_image': True}"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button string='Next' name="branch_config" attrs="{'invisible': [('state', '!=', 'draft')]}" type="object" class="btn-primary"/>
|
||||
<button string='Finish' name="finish_branch_config" attrs="{'invisible': [('state', '=', 'draft')]}" type="object" class="btn-primary"/>
|
||||
<button string="Cancel" class="btn-default" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_branch_config" model="ir.actions.act_window">
|
||||
<field name="name">Branch Configuration</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">branch.config</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
</flectra>
|
@ -63,6 +63,7 @@
|
||||
<field name="team_type" groups="base.group_no_one"/>
|
||||
<field name="user_id" domain="[('share', '=', False)]"/>
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
<field name="branch_id" options="{'no_create': True}" groups="base_branch_company.group_multi_branch"/>
|
||||
</group>
|
||||
<group name="right">
|
||||
</group>
|
||||
|
Loading…
Reference in New Issue
Block a user