[FIX]: Branch: Record rule, set branch in warehouse when create company, set branch in defualt company and misc

This commit is contained in:
Haresh Chavda 2018-08-10 14:35:39 +05:30
parent d2d959f597
commit 77a7f4aa24
6 changed files with 18 additions and 13 deletions

View File

@ -19,5 +19,9 @@
<field name='default_branch_id' ref='data_branch_1'/> <field name='default_branch_id' ref='data_branch_1'/>
</record> </record>
<record id="base.main_company" model="res.company">
<field name='branch_id' ref='data_branch_1'/>
</record>
</data> </data>
</flectra> </flectra>

View File

@ -16,6 +16,7 @@ def migrate_company_branch(cr, registry):
'branch_ids': [(6, 0, [user_id.company_id.branch_id.id])]}) 'branch_ids': [(6, 0, [user_id.company_id.branch_id.id])]})
cr.commit() cr.commit()
class Company(models.Model): class Company(models.Model):
_name = "res.company" _name = "res.company"
_inherit = ["res.company"] _inherit = ["res.company"]
@ -129,7 +130,7 @@ class Users(models.Model):
string="Number of Companies", default=_branches_count) string="Number of Companies", default=_branches_count)
@api.onchange('company_id') @api.onchange('company_id')
def _onchange_address(self): def _onchange_company_id(self):
self.default_branch_id = self.company_id.branch_id.id self.default_branch_id = self.company_id.branch_id.id
self.branch_ids = [(4, self.company_id.branch_id.id)] self.branch_ids = [(4, self.company_id.branch_id.id)]

View File

@ -7,7 +7,7 @@ from dateutil.relativedelta import relativedelta
from flectra import api, fields, models, SUPERUSER_ID, _ from flectra import api, fields, models, SUPERUSER_ID, _
from flectra.tools import DEFAULT_SERVER_DATETIME_FORMAT from flectra.tools import DEFAULT_SERVER_DATETIME_FORMAT
from flectra.tools.float_utils import float_is_zero, float_compare from flectra.tools.float_utils import float_is_zero, float_compare
from flectra.exceptions import UserError, AccessError from flectra.exceptions import UserError, AccessError, ValidationError
from flectra.tools.misc import formatLang from flectra.tools.misc import formatLang
from flectra.addons.base.res.res_partner import WARNING_MESSAGE, WARNING_HELP from flectra.addons.base.res.res_partner import WARNING_MESSAGE, WARNING_HELP
from flectra.addons import decimal_precision as dp from flectra.addons import decimal_precision as dp

View File

@ -43,7 +43,7 @@
<record model="ir.rule" id="crm_team_multi_branch_rule"> <record model="ir.rule" id="crm_team_multi_branch_rule">
<field name="name">CRM Team multi-branch</field> <field name="name">CRM Team multi-branch</field>
<field name="model_id" ref="sales_team.model_crm_team"/> <field name="model_id" ref="sales_team.model_crm_team"/>
<field name="global" eval="True"/> <field name="groups" eval="[(4, ref('base_branch_company.group_multi_branch'))]"/>
<field name="domain_force">['|',('branch_id','=', False),'|',('branch_id','=',user.default_branch_id.id), ('branch_id','in', [b.id for b in user.branch_ids])]</field> <field name="domain_force">['|',('branch_id','=', False),'|',('branch_id','=',user.default_branch_id.id), ('branch_id','in', [b.id for b in user.branch_ids])]</field>
</record> </record>

View File

@ -41,5 +41,5 @@ class Company(models.Model):
company.create_transit_location() company.create_transit_location()
# mutli-company rules prevents creating warehouse and sub-locations # mutli-company rules prevents creating warehouse and sub-locations
self.env['stock.warehouse'].check_access_rights('create') self.env['stock.warehouse'].check_access_rights('create')
self.env['stock.warehouse'].sudo().create({'name': company.name, 'code': company.name[:5], 'company_id': company.id, 'partner_id': company.partner_id.id}) self.env['stock.warehouse'].sudo().create({'name': company.name, 'code': company.name[:5], 'company_id': company.id, 'branch_id': company.branch_id.id, 'partner_id': company.partner_id.id})
return company return company

View File

@ -4,24 +4,25 @@
!python {model: account.journal, id: False} : | !python {model: account.journal, id: False} : |
#if we already have a coa installed, create journal and set property field #if we already have a coa installed, create journal and set property field
company_obj = self.env['res.company'] company_obj = self.env['res.company']
company_ids = company_obj.search([('chart_template_id', '!=', False)]).ids company_ids = company_obj.search([('chart_template_id', '!=', False)])
for company_id in company_ids: for company_id in company_ids:
from flectra.tools.translate import _ from flectra.tools.translate import _
#Check if property exists for stock account journal exists #Check if property exists for stock account journal exists
PropertyObj = self.env['ir.property'] PropertyObj = self.env['ir.property']
properties = PropertyObj.search([('name', '=', 'property_stock_journal'), ('company_id', '=', company_id)]) properties = PropertyObj.search([('name', '=', 'property_stock_journal'), ('company_id', '=', company_id.id)])
AccountJournal = self.env['account.journal'] AccountJournal = self.env['account.journal']
#If not, check if you can find a journal that is already there with the same name, otherwise create one #If not, check if you can find a journal that is already there with the same name, otherwise create one
if not properties: if not properties:
journal_id = AccountJournal.search([('name', '=', _('Stock Journal')), ('company_id', '=', company_id), ('type', '=', 'general')], limit=1).id journal_id = AccountJournal.search([('name', '=', _('Stock Journal')), ('company_id', '=', company_id.id), ('type', '=', 'general')], limit=1).id
if not journal_id: if not journal_id:
journal_id = AccountJournal.create({ journal_id = AccountJournal.create({
'name': _('Stock Journal'), 'name': _('Stock Journal'),
'type': 'general', 'type': 'general',
'code': 'STJ', 'code': 'STJ',
'company_id': company_id, 'company_id': company_id.id,
'branch_id': company_id.branch_id.id,
'show_on_dashboard': False 'show_on_dashboard': False
}).id }).id
vals = {'name': 'property_stock_journal', vals = {'name': 'property_stock_journal',
@ -29,7 +30,7 @@
('name', '=', 'property_stock_journal'), ('name', '=', 'property_stock_journal'),
('model', '=', 'product.category'), ('model', '=', 'product.category'),
('relation', '=', 'account.journal')], limit=1).id, ('relation', '=', 'account.journal')], limit=1).id,
'company_id': company_id, 'company_id': company_id.id,
'value': 'account.journal,' + str(journal_id)} 'value': 'account.journal,' + str(journal_id)}
PropertyObj.create(vals) PropertyObj.create(vals)
@ -39,9 +40,8 @@
'property_stock_account_output_categ_id', 'property_stock_account_output_categ_id',
'property_stock_valuation_account_id', 'property_stock_valuation_account_id',
] ]
company = company_obj.browse(company_id)
for record in todo_list: for record in todo_list:
account = getattr(company, record) account = getattr(company_id, record)
value = account and 'account.account,' + str(account.id) or False value = account and 'account.account,' + str(account.id) or False
if value: if value:
field_id = self.env['ir.model.fields'].search([ field_id = self.env['ir.model.fields'].search([
@ -51,11 +51,11 @@
], limit=1).id ], limit=1).id
vals = { vals = {
'name': record, 'name': record,
'company_id': company_id, 'company_id': company_id.id,
'fields_id': field_id, 'fields_id': field_id,
'value': value, 'value': value,
} }
properties = PropertyObj.search([('name', '=', record), ('company_id', '=', company.id)], limit=1) properties = PropertyObj.search([('name', '=', record), ('company_id', '=', company_id.id)], limit=1)
if not properties: if not properties:
# create the property # create the property
PropertyObj.create(vals) PropertyObj.create(vals)