[FIX]: Branch: Record rule, set branch in warehouse when create company, set branch in defualt company and misc
This commit is contained in:
parent
d2d959f597
commit
77a7f4aa24
@ -19,5 +19,9 @@
|
||||
<field name='default_branch_id' ref='data_branch_1'/>
|
||||
</record>
|
||||
|
||||
<record id="base.main_company" model="res.company">
|
||||
<field name='branch_id' ref='data_branch_1'/>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</flectra>
|
||||
|
@ -16,6 +16,7 @@ def migrate_company_branch(cr, registry):
|
||||
'branch_ids': [(6, 0, [user_id.company_id.branch_id.id])]})
|
||||
cr.commit()
|
||||
|
||||
|
||||
class Company(models.Model):
|
||||
_name = "res.company"
|
||||
_inherit = ["res.company"]
|
||||
@ -129,7 +130,7 @@ class Users(models.Model):
|
||||
string="Number of Companies", default=_branches_count)
|
||||
|
||||
@api.onchange('company_id')
|
||||
def _onchange_address(self):
|
||||
def _onchange_company_id(self):
|
||||
self.default_branch_id = self.company_id.branch_id.id
|
||||
self.branch_ids = [(4, self.company_id.branch_id.id)]
|
||||
|
||||
|
@ -7,7 +7,7 @@ from dateutil.relativedelta import relativedelta
|
||||
from flectra import api, fields, models, SUPERUSER_ID, _
|
||||
from flectra.tools import DEFAULT_SERVER_DATETIME_FORMAT
|
||||
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.addons.base.res.res_partner import WARNING_MESSAGE, WARNING_HELP
|
||||
from flectra.addons import decimal_precision as dp
|
||||
|
@ -43,7 +43,7 @@
|
||||
<record model="ir.rule" id="crm_team_multi_branch_rule">
|
||||
<field name="name">CRM Team multi-branch</field>
|
||||
<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>
|
||||
</record>
|
||||
|
||||
|
@ -41,5 +41,5 @@ class Company(models.Model):
|
||||
company.create_transit_location()
|
||||
# mutli-company rules prevents creating warehouse and sub-locations
|
||||
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
|
||||
|
@ -4,24 +4,25 @@
|
||||
!python {model: account.journal, id: False} : |
|
||||
#if we already have a coa installed, create journal and set property field
|
||||
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:
|
||||
from flectra.tools.translate import _
|
||||
|
||||
#Check if property exists for stock account journal exists
|
||||
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']
|
||||
|
||||
#If not, check if you can find a journal that is already there with the same name, otherwise create one
|
||||
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:
|
||||
journal_id = AccountJournal.create({
|
||||
'name': _('Stock Journal'),
|
||||
'type': 'general',
|
||||
'code': 'STJ',
|
||||
'company_id': company_id,
|
||||
'company_id': company_id.id,
|
||||
'branch_id': company_id.branch_id.id,
|
||||
'show_on_dashboard': False
|
||||
}).id
|
||||
vals = {'name': 'property_stock_journal',
|
||||
@ -29,7 +30,7 @@
|
||||
('name', '=', 'property_stock_journal'),
|
||||
('model', '=', 'product.category'),
|
||||
('relation', '=', 'account.journal')], limit=1).id,
|
||||
'company_id': company_id,
|
||||
'company_id': company_id.id,
|
||||
'value': 'account.journal,' + str(journal_id)}
|
||||
|
||||
PropertyObj.create(vals)
|
||||
@ -39,9 +40,8 @@
|
||||
'property_stock_account_output_categ_id',
|
||||
'property_stock_valuation_account_id',
|
||||
]
|
||||
company = company_obj.browse(company_id)
|
||||
for record in todo_list:
|
||||
account = getattr(company, record)
|
||||
account = getattr(company_id, record)
|
||||
value = account and 'account.account,' + str(account.id) or False
|
||||
if value:
|
||||
field_id = self.env['ir.model.fields'].search([
|
||||
@ -51,11 +51,11 @@
|
||||
], limit=1).id
|
||||
vals = {
|
||||
'name': record,
|
||||
'company_id': company_id,
|
||||
'company_id': company_id.id,
|
||||
'fields_id': field_id,
|
||||
'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:
|
||||
# create the property
|
||||
PropertyObj.create(vals)
|
||||
|
Loading…
Reference in New Issue
Block a user