[IMP] account,sale:checked multi-company in accounting and sale module

bzr revid: mtr@mtr-20100608064531-6q96hu7uet2e5qc9
This commit is contained in:
mtr 2010-06-08 12:15:31 +05:30
parent fcc0296fff
commit af6e99a052
5 changed files with 158 additions and 118 deletions

View File

@ -513,6 +513,10 @@ class account_account(osv.osv):
self._check_moves(cr, uid, ids, "write", context)
if 'type' in vals.keys():
self._check_allow_type_change(cr, uid, ids, vals['type'], context=context)
if 'company_id' in vals:
obj=self.pool.get('account.move.line').search(cr, uid, [('account_id', '=', ids)])
if obj:
raise osv.except_osv(_('Warning !'), _('You cannot update Company as its related record exist in Entry Lines'))
return super(account_account, self).write(cr, uid, ids, vals, context=context)
def unlink(self, cr, uid, ids, context={}):
@ -711,7 +715,7 @@ class account_period(osv.osv):
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True, states={'done':[('readonly',True)]}, select=True),
'state': fields.selection([('draft','Draft'), ('done','Done')], 'State', readonly=True,
help='When monthly periods are created. The state is \'Draft\'. At the end of monthly period it is in \'Done\' state.'),
'company_id': fields.many2one('res.company', 'Company', required=True)
'company_id': fields.related('fiscalyear_id','company_id',type='many2one',relation='res.company',string='Company',store=True)
}
_defaults = {
'state': lambda *a: 'draft',
@ -784,6 +788,14 @@ class account_period(osv.osv):
ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit)
return self.name_get(cr, user, ids, context=context)
def write(self, cr, uid, ids, vals, context=None):
obj=[]
if 'company_id' in vals:
obj=self.pool.get('account.move.line').search(cr, uid, [('period_id', '=', ids)])
if obj:
raise osv.except_osv(_('Warning !'), _('You cannot update Company as its related record exist in Entry Lines'))
return super(account_period, self).write(cr, uid, ids, vals, context=context)
account_period()
class account_journal_period(osv.osv):
@ -809,7 +821,7 @@ class account_journal_period(osv.osv):
'state': fields.selection([('draft','Draft'), ('printed','Printed'), ('done','Done')], 'State', required=True, readonly=True,
help='When journal period is created. The state is \'Draft\'. If a report is printed it comes to \'Printed\' state. When all transactions are done, it comes in \'Done\' state.'),
'fiscalyear_id': fields.related('period_id', 'fiscalyear_id', string='Fiscal Year', type='many2one', relation='account.fiscalyear'),
'company_id' : fields.many2one('res.company', 'Company')
'company_id': fields.related('journal_id','company_id',type='many2one',relation='res.company',string='Company')
}
def _check(self, cr, uid, ids, context={}):

View File

@ -498,9 +498,17 @@ class account_move_line(osv.osv):
return False
return True
def _check_company_id(self, cr, uid, ids):
lines = self.browse(cr, uid, ids)
for l in lines:
if l.company_id == l.account_id.company_id and l.company_id == l.period_id.company_id:
return True
return False
_constraints = [
(_check_no_view, 'You can not create move line on view account.', ['account_id']),
(_check_no_closed, 'You can not create move line on closed account.', ['account_id']),
(_check_company_id,'Company must be same for its related account and period.',['company_id'] ),
]
#TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
@ -574,6 +582,14 @@ class account_move_line(osv.osv):
unmerge = []
total = 0.0
merges_rec = []
flag=False
for line in self.browse(cr, uid, ids, context.get('active_ids')):
for line1 in self.browse(cr, uid, ids, context.get('active_ids')):
if line1.company_id == line.company_id:
flag=True
else:
raise osv.except_osv(_('Warning !'), _('To reconcile the records Company must be the same'))
if flag:
for line in self.browse(cr, uid, ids, context):
if line.reconcile_id:
raise osv.except_osv(_('Warning'), _('Already Reconciled!'))
@ -587,6 +603,7 @@ class account_move_line(osv.osv):
else:
unmerge.append(line.id)
total += (line.debit or 0.0) - (line.credit or 0.0)
if not total:
res = self.reconcile(cr, uid, merges+unmerge, context=context)
return res
@ -604,6 +621,14 @@ class account_move_line(osv.osv):
currency = 0.0
account_id = False
partner_id = False
flag=False
for line in self.browse(cr, uid, ids, context.get('active_ids')):
for line1 in self.browse(cr, uid, ids, context.get('active_ids')):
if line1.company_id == line.company_id:
flag=True
else:
raise osv.except_osv(_('Warning !'), _('To reconcile the records Company must be the same'))
if flag:
for line in unrec_lines:
if line.state <> 'valid':
raise osv.except_osv(_('Error'),

View File

@ -39,6 +39,7 @@ class sale_shop(osv.osv):
'warehouse_id': fields.many2one('stock.warehouse', 'Warehouse'),
'pricelist_id': fields.many2one('product.pricelist', 'Pricelist'),
'project_id': fields.many2one('account.analytic.account', 'Analytic Account'),
'company_id': fields.many2one('res.company', 'Company'),
}
sale_shop()
@ -277,7 +278,7 @@ class sale_order(osv.osv):
'invoice_quantity': fields.selection([('order', 'Ordered Quantities'), ('procurement', 'Shipped Quantities')], 'Invoice on', help="The sale order will automatically create the invoice proposition (draft invoice). Ordered and delivered quantities may not be the same. You have to choose if you invoice based on ordered or shipped quantities. If the product is a service, shipped quantities means hours spent on the associated tasks.", required=True),
'payment_term': fields.many2one('account.payment.term', 'Payment Term'),
'fiscal_position': fields.many2one('account.fiscal.position', 'Fiscal Position'),
'company_id': fields.many2one('res.company','Company',select=1),
'company_id': fields.related('shop_id','company_id',type='many2one',relation='res.company',string='Company',store=True)
}
_defaults = {
'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'sale.order', context=c),

View File

@ -16,6 +16,7 @@
<field model="res.company" name="name" search="[]" use="name"/>
<field model="stock.warehouse" name="warehouse_id" search="[]"/>
<field model="account.payment.term" name="payment_default_id" search="[]"/>
<field model="res.company" name="company_id" search="[]"/>
</record>
<function eval="('default',False,'shop_id', [('sale.order', False)], shop, True, False, False, False, True)" id="sale_default_set" model="ir.values" name="set"/>

View File

@ -14,6 +14,7 @@
<form string="Sale Shop">
<field name="name" select="1"/>
<field name="warehouse_id" required="1" select="1" widget="selection"/>
<field name="company_id"/>
<separator colspan="4" string="Accounting"/>
<field name="payment_default_id"/>
<field domain="[('type','=','sale')]" name="pricelist_id" select="1"/>