[MERGE] merge mtr branch for changes of multicompany environement with account move lines

[IMP] optimize the code

bzr revid: mra@mra-laptop-20100609132253-giau5tgcdlcoh6aq
This commit is contained in:
Mustufa Rangwala 2010-06-09 18:52:53 +05:30
commit 9148775b6e
5 changed files with 54 additions and 7 deletions

View File

@ -509,8 +509,13 @@ class account_account(osv.osv):
def write(self, cr, uid, ids, vals, context=None):
if context is None:
context = {}
if 'company_id' in vals:
move_lines = self.pool.get('account.move.line').search(cr, uid, [('account_id', 'in', ids)])
if move_lines:
raise osv.except_osv(_('Warning !'), _('You cannot modify Company of account as its related record exist in Entry Lines'))
if 'active' in vals and not vals['active']:
self._check_moves(cr, uid, ids, "write", context)
self._check_moves(cr, uid, ids, "write", context=context)
if 'type' in vals.keys():
self._check_allow_type_change(cr, uid, ids, vals['type'], context=context)
return super(account_account, self).write(cr, uid, ids, vals, context=context)
@ -593,6 +598,14 @@ class account_journal(osv.osv):
'user_id': lambda self,cr,uid,context: uid,
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
}
def write(self, cr, uid, ids, vals, context=None):
obj=[]
if 'company_id' in vals:
move_lines = self.pool.get('account.move.line').search(cr, uid, [('journal_id', 'in', ids)])
if move_lines:
raise osv.except_osv(_('Warning !'), _('You cannot modify company of this journal as its related record exist in Entry Lines'))
return super(account_period, self).write(cr, uid, ids, vals, context=context)
def create(self, cr, uid, vals, context={}):
journal_id = super(account_journal, self).create(cr, uid, vals, context)
# journal_name = self.browse(cr, uid, [journal_id])[0].code
@ -711,7 +724,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 +797,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:
move_lines = self.pool.get('account.move.line').search(cr, uid, [('period_id', 'in', ids)])
if move_lines:
raise osv.except_osv(_('Warning !'), _('You cannot modify company of this period 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 +830,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 or l.company_id != l.period_id.company_id:
return False
return True
_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,13 @@ class account_move_line(osv.osv):
unmerge = []
total = 0.0
merges_rec = []
company_list = []
for line in self.browse(cr, uid, ids, context=context):
if not line.company_id in company_list:
raise osv.except_osv(_('Warning !'), _('To reconcile the entries company should be the same for all entries'))
company_list.append(line.company_id)
for line in self.browse(cr, uid, ids, context):
if line.reconcile_id:
raise osv.except_osv(_('Warning'), _('Already Reconciled!'))
@ -587,6 +602,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 +620,13 @@ class account_move_line(osv.osv):
currency = 0.0
account_id = False
partner_id = False
company_list = []
for line in self.browse(cr, uid, ids, context=context):
if not line.company_id in company_list:
raise osv.except_osv(_('Warning !'), _('To reconcile the entries company should be the same for all entries'))
company_list.append(line.company_id)
for line in unrec_lines:
if line.state <> 'valid':
raise osv.except_osv(_('Error'),
@ -836,7 +859,7 @@ class account_move_line(osv.osv):
if vals.get('date', False):
todo_date = vals['date']
del vals['date']
for line in self.browse(cr, uid, ids,context=context):
ctx = context.copy()
if ('journal_id' not in ctx):
@ -848,8 +871,8 @@ class account_move_line(osv.osv):
if line.move_id:
ctx['period_id'] = line.move_id.period_id.id
else:
ctx['period_id'] = line.period_id.id
#Check for centralisation
ctx['period_id'] = line.period_id.id
#Check for centralisation
journal = self.pool.get('account.journal').browse(cr, uid, ctx['journal_id'], context=ctx)
if journal.centralisation:
self._check_moves(cr, uid, context=ctx)

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" widget='selection'/>
<separator colspan="4" string="Accounting"/>
<field name="payment_default_id"/>
<field domain="[('type','=','sale')]" name="pricelist_id" select="1"/>