##############################################################################
import time
-from datetime import datetime, timedelta
+from datetime import datetime
from dateutil.relativedelta import relativedelta
from operator import itemgetter
import pooler
from osv import fields, osv
import decimal_precision as dp
-from tools.misc import currency
from tools.translate import _
-from tools import config
def check_cycle(self, cr, uid, ids):
""" climbs the ``self._table.parent_id`` chains for 100 levels or
}
_order = "name"
- def compute(self, cr, uid, id, value, date_ref=False, context={}):
+ def compute(self, cr, uid, id, value, date_ref=False, context=None):
if not date_ref:
date_ref = datetime.now().strftime('%Y-%m-%d')
- pt = self.browse(cr, uid, id, context)
+ pt = self.browse(cr, uid, id, context=context)
amount = value
result = []
+ obj_precision = self.pool.get('decimal.precision')
for line in pt.line_ids:
- prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
+ prec = obj_precision.precision_get(cr, uid, 'Account')
if line.value == 'fixed':
amt = round(line.value_amount, prec)
elif line.value == 'procent':
if amt:
next_date = (datetime.strptime(date_ref, '%Y-%m-%d') + relativedelta(days=line.days))
if line.days2 < 0:
- nyear = next_date.strftime("%Y")
- nmonth = str(int(next_date.strftime("%m"))% 12+1)
- nday = "1"
-
- ndate = "%s-%s-%s" % (nyear, nmonth, nday)
- nseconds = time.mktime(time.strptime(ndate, '%Y-%m-%d'))
- next_month = datetime.fromtimestamp(nseconds)
-
- delta = timedelta(seconds=1)
- next_date = next_month - delta
- next_date = next_date + relativedelta(days=line.days2)
+ next_first_date = next_date + relativedelta(day=1,months=1) #Getting 1st of next month
+ next_date = next_first_date + relativedelta(days=line.days2)
if line.days2 > 0:
next_date += relativedelta(day=line.days2, months=1)
result.append( (next_date.strftime('%Y-%m-%d'), amt) )
}
_order = "sequence"
- def _check_percent(self, cr, uid, ids, context={}):
+ def _check_percent(self, cr, uid, ids, context=None):
obj = self.browse(cr, uid, ids[0])
if obj.value == 'procent' and ( obj.value_amount < 0.0 or obj.value_amount > 1.0):
return False
('expense','Profit & Loss (Expense Accounts)'),
('asset','Balance Sheet (Assets Accounts)'),
('liability','Balance Sheet (Liability Accounts)')
- ],'Type Heads', select=True, readonly=False, help="According value related accounts will be display on respective reports (Balance Sheet Profit & Loss Account)"),
+ ],'P&L / BS Category', select=True, readonly=False, help="According value related accounts will be display on respective reports (Balance Sheet Profit & Loss Account)", required=True),
'note': fields.text('Description'),
}
_defaults = {
'close_method': 'none',
'sign': 1,
+ 'report_type': 'none',
}
_order = "code"
account_account_type()
-def _code_get(self, cr, uid, context={}):
+def _code_get(self, cr, uid, context=None):
acc_type_obj = self.pool.get('account.account.type')
ids = acc_type_obj.search(cr, uid, [])
- res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context)
+ res = acc_type_obj.read(cr, uid, ids, ['code', 'name'], context=context)
return [(r['code'], r['name']) for r in res]
#----------------------------------------------------------
# ON l.account_id = tmp.id
# or make _get_children_and_consol return a query and join on that
request = ("SELECT l.account_id as id, " +\
- ' , '.join(map(mapping.__getitem__, field_names)) +
+ ', '.join(map(mapping.__getitem__, field_names)) +
" FROM account_move_line l" \
" WHERE l.account_id IN %s " \
+ filters +
accounts = self.browse(cr, uid, ids)
for account in accounts:
level = 0
- if account.parent_id :
+ if account.parent_id:
obj = self.browse(cr, uid, account.parent_id.id)
level = obj.level + 1
res[account.id] = level
if not ids:
ids = self.search(cr, user, [('name', operator, name)]+ args, limit=limit)
if not ids and len(name.split()) >= 2:
- ids = self.search(cr, user, [('code', operator, name.split()[0]), ('name', operator, name.split()[1])]+ args, limit=limit)
+ #Separating code and name of account for searching
+ operand1,operand2 = name.split(' ',1) #name can contain spaces e.g. OpenERP S.A.
+ ids = self.search(cr, user, [('code', operator, operand1), ('name', operator, operand2)]+ args, limit=limit)
else:
ids = self.search(cr, user, args, context=context, limit=limit)
return self.name_get(cr, user, ids, context=context)
- def name_get(self, cr, uid, ids, context={}):
- if not len(ids):
+ def name_get(self, cr, uid, ids, context=None):
+ if not ids:
return []
- reads = self.read(cr, uid, ids, ['name', 'code'], context)
+ reads = self.read(cr, uid, ids, ['name', 'code'], context=context)
res = []
for record in reads:
name = record['name']
res.append((record['id'], name))
return res
- def copy(self, cr, uid, id, default={}, context={}, done_list=[], local=False):
+ def copy(self, cr, uid, id, default={}, context=None, done_list=[], local=False):
account = self.browse(cr, uid, id, context=context)
new_child_ids = []
if not default:
class account_journal_column(osv.osv):
- def _col_get(self, cr, user, context={}):
+
+ def _col_get(self, cr, user, context=None):
result = []
cols = self.pool.get('account.move.line')._columns
for col in cols:
if col in ('period_id', 'journal_id'):
continue
-
result.append( (col, cols[col].string) )
result.sort()
return result
+
_name = "account.journal.column"
_description = "Journal Column"
_columns = {
_columns = {
'name': fields.char('Journal Name', size=64, required=True, translate=True),
'code': fields.char('Code', size=16, required=True, help="The code will be used to generate the numbers of the journal entries of this journal."),
- 'type': fields.selection([('sale', 'Sale'),('sale_refund','Sale Refund'), ('purchase', 'Purchase'), ('purchase_refund','Purchase Refund'), ('cash', 'Cash'), ('bank', 'Bank and Cheques'), ('general', 'General'), ('situation', 'Situation')], 'Type', size=32, required=True,
+ 'type': fields.selection([('sale', 'Sale'),('sale_refund','Sale Refund'), ('purchase', 'Purchase'), ('purchase_refund','Purchase Refund'), ('cash', 'Cash'), ('bank', 'Bank and Cheques'), ('general', 'General'), ('situation', 'Opening/Closing Situation')], 'Type', size=32, required=True,
help="Select 'Sale' for Sale journal to be used at the time of making invoice."\
" Select 'Purchase' for Purchase Journal to be used at the time of approving purchase order."\
" Select 'Cash' to be used at the time of making payment."\
- " Select 'General' to be used at the time of stock input/output."\
- " Select 'Situation' to be used at the time of making vouchers."),
+ " Select 'General' for miscellaneous operations."\
+ " Select 'Opening/Closing Situation' to be used at the time of new fiscal year creation or end of year entries generation."),
'refund_journal': fields.boolean('Refund Journal', help='Fill this if the journal is to be used for refunds of invoices.'),
'type_control_ids': fields.many2many('account.account.type', 'account_journal_type_rel', 'journal_id','type_id', 'Type Controls', domain=[('code','<>','view'), ('code', '<>', 'closed')]),
'account_control_ids': fields.many2many('account.account', 'account_account_type_rel', 'journal_id','account_id', 'Account', domain=[('type','<>','view'), ('type', '<>', 'closed')]),
'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,
}
+ _sql_constraints = [
+ ('code_company_uniq', 'unique (code, company_id)', 'The code of the journal must be unique per company !'),
+ ('name_company_uniq', 'unique (name, company_id)', 'The name of the journal must be unique per company !'),
+ ]
+
+ _order = 'code'
+
+ def copy(self, cr, uid, id, default={}, context=None, done_list=[], local=False):
+ journal = self.browse(cr, uid, id, context=context)
+ if not default:
+ default = {}
+ default = default.copy()
+ default['code'] = (journal['code'] or '') + '(copy)'
+ default['name'] = (journal['name'] or '') + '(copy)'
+ return super(account_journal, self).copy(cr, uid, id, default, 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, [('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_journal, self).write(cr, uid, ids, vals, context=context)
- def create_sequence(self, cr, uid, vals, context={}):
+ def create_sequence(self, cr, uid, vals, context=None):
"""
Create new entry sequence for every new Joural
@param cr: cursor to database
@param context: context arguments, like lang, time zone
@return: return a result
"""
-
- journal_type = ('sale', 'sale_refund', 'purchase', 'purchase_refund')
- journal_seq = {
- 'sale':'seq_out_invoice',
- 'purchase':'seq_in_invoice',
- 'purchase_refund':'seq_out_refund',
- 'sale_refund':'seq_in_refund'
- }
-
seq_pool = self.pool.get('ir.sequence')
seq_typ_pool = self.pool.get('ir.sequence.type')
- date_pool = self.pool.get('ir.model.data')
- result = True
name = vals['name']
code = vals['code'].lower()
'name': name,
'code': code
}
- type_id = seq_typ_pool.create(cr, uid, types)
+ seq_typ_pool.create(cr, uid, types)
seq = {
'name': name,
}
return seq_pool.create(cr, uid, seq)
- def create(self, cr, uid, vals, context={}):
+ def create(self, cr, uid, vals, context=None):
if not 'sequence_id' in vals or not vals['sequence_id']:
- vals.update({'sequence_id' : self.create_sequence(cr, uid, vals, context)})
+ vals.update({'sequence_id': self.create_sequence(cr, uid, vals, context)})
return super(account_journal, self).create(cr, uid, vals, context)
- def name_get(self, cr, user, ids, context={}):
+ def name_get(self, cr, user, ids, context=None):
"""
Returns a list of tupples containing id, name.
- result format : {[(id, name), (id, name), ...]}
+ result format: {[(id, name), (id, name), ...]}
@param cr: A database cursor
@param user: ID of the user currently logged in
return self.name_get(cr, user, ids, context=context)
def onchange_type(self, cr, uid, ids, type, currency):
- data_pool = self.pool.get('ir.model.data')
+ obj_data = self.pool.get('ir.model.data')
user_pool = self.pool.get('res.users')
type_map = {
if type in ('cash', 'bank') and currency and user.company_id.currency_id.id != currency:
view_id = 'account_journal_bank_view_multi'
- data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=',view_id)])
- data = data_pool.browse(cr, uid, data_id[0])
+ data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=',view_id)])
+ data = obj_data.browse(cr, uid, data_id[0])
res.update({
'centralisation':type == 'situation',
'date_start': fields.date('Start of Period', required=True, states={'done':[('readonly',True)]}),
'date_stop': fields.date('End of Period', required=True, states={'done':[('readonly',True)]}),
'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,
+ 'state': fields.selection([('draft','Open'), ('done','Closed')], '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.related('fiscalyear_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True)
}
return self.name_get(cr, user, ids, context=context)
def write(self, cr, uid, ids, vals, context={}):
- 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)
+ def build_ctx_periods(self, cr, uid, period_from_id, period_to_id):
+ period_from = self.browse(cr, uid, period_from_id)
+ period_date_start = period_from.date_start
+ company1_id = period_from.company_id.id
+ period_to = self.browse(cr, uid, period_to_id)
+ period_date_stop = period_to.date_stop
+ company2_id = period_to.company_id.id
+ if company1_id != company2_id:
+ raise osv.except_osv(_('Error'), _('You should have chosen periods that belongs to the same company'))
+ if period_date_start > period_date_stop:
+ raise osv.except_osv(_('Error'), _('Start period should be smaller then End period'))
+ return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id)])
+
account_period()
class account_journal_period(osv.osv):
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
"""
Returns a list of tupples containing id, name, as internally it is called {def name_get}
- result format : {[(id, name), (id, name), ...]}
+ result format: {[(id, name), (id, name), ...]}
@param cr: A database cursor
@param user: ID of the user currently logged in
return self.name_get(cr, user, ids, context=context)
def name_get(self, cursor, user, ids, context=None):
- if not len(ids):
+ if isinstance(ids, (int, long)):
+ ids = [ids]
+ if not ids:
return []
res = []
data_move = self.pool.get('account.move').browse(cursor,user,ids)
if cond[1] in ['=like', 'like', 'not like', 'ilike', 'not ilike', 'in', 'not in', 'child_of']:
continue
- cr.execute("select move_id from account_move_line group by move_id having sum(debit) %s %%s" % (cond[1]) ,(amount,))
+ cr.execute("select move_id from account_move_line group by move_id having sum(debit) %s %%s" % (cond[1]),(amount,))
res_ids = set(id[0] for id in cr.fetchall())
ids = ids and (ids & res_ids) or res_ids
if ids:
help='All manually created new journal entry are usually in the state \'Unposted\', but you can set the option to skip that state on the related journal. In that case, they will be behave as journal entries automatically created by the system on document validation (invoices, bank statements...) and will be created in \'Posted\' state.'),
'line_id': fields.one2many('account.move.line', 'move_id', 'Entries', states={'posted':[('readonly',True)]}),
'to_check': fields.boolean('To Review', help='Check this box if you are unsure of that journal entry and if you want to note it as \'to be reviewed\' by an accounting expert.'),
- 'partner_id': fields.related('line_id', 'partner_id', type="many2one", relation="res.partner", string="Partner"),
+ 'partner_id': fields.related('line_id', 'partner_id', type="many2one", relation="res.partner", string="Partner", store=True),
'amount': fields.function(_amount_compute, method=True, string='Amount', digits_compute=dp.get_precision('Account'), type='float', fnct_search=_search_amount),
'date': fields.date('Date', required=True, states={'posted':[('readonly',True)]}),
'narration':fields.text('Narration'),
'name': '/',
'state': 'draft',
'period_id': _get_period,
- 'date': time.strftime('%Y-%m-%d'),
+ 'date': lambda *a: time.strftime('%Y-%m-%d'),
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
}
]
def post(self, cr, uid, ids, context=None):
+ if context is None:
+ context = {}
invoice = context.get('invoice', False)
valid_moves = self.validate(cr, uid, ids, context)
- if valid_moves:
- for move in self.browse(cr, uid, valid_moves):
- if move.name =='/':
- new_name = False
- journal = move.journal_id
-
- if invoice and invoice.internal_number:
- new_name = invoice.internal_number
+
+ if not valid_moves:
+ raise osv.except_osv(_('Integrity Error !'), _('You cannot validate a non-balanced entry !\nMake sure you have configured Payment Term properly !\nIt should contain atleast one Payment Term Line with type "Balance" !'))
+ obj_sequence = self.pool.get('ir.sequence')
+ for move in self.browse(cr, uid, valid_moves):
+ if move.name =='/':
+ new_name = False
+ journal = move.journal_id
+
+ if invoice and invoice.internal_number:
+ new_name = invoice.internal_number
+ else:
+ if journal.sequence_id:
+ c = {'fiscalyear_id': move.period_id.fiscalyear_id.id}
+ new_name = obj_sequence.get_id(cr, uid, journal.sequence_id.id, context=c)
else:
- if journal.sequence_id:
- c = {'fiscalyear_id': move.period_id.fiscalyear_id.id}
- new_name = self.pool.get('ir.sequence').get_id(cr, uid, journal.sequence_id.id, context=c)
- else:
- raise osv.except_osv(_('Error'), _('No sequence defined in the journal !'))
+ raise osv.except_osv(_('Error'), _('No sequence defined on the journal !'))
- if new_name:
- self.write(cr, uid, [move.id], {'name':new_name})
+ if new_name:
+ self.write(cr, uid, [move.id], {'name':new_name})
+
+ cr.execute('UPDATE account_move '\
+ 'SET state=%s '\
+ 'WHERE id IN %s',
+ ('posted', tuple(valid_moves),))
- cr.execute('UPDATE account_move '\
- 'SET state=%s '\
- 'WHERE id IN %s',
- ('posted', tuple(valid_moves),))
- else:
- raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !\nMake sure you have configured Payment Term properly !\nIt should contain atleast one Payment Term Line with type "Balance" !'))
return True
def button_validate(self, cursor, user, ids, context=None):
for line in self.browse(cr, uid, ids, context):
if not line.journal_id.update_posted:
raise osv.except_osv(_('Error !'), _('You can not modify a posted entry of this journal !\nYou should set the journal to allow cancelling entries if you want to do that.'))
- if len(ids):
+ if ids:
cr.execute('UPDATE account_move '\
'SET state=%s '\
'WHERE id IN %s', ('draft', tuple(ids),))
#
# TODO: Check if period is closed !
#
- def create(self, cr, uid, vals, context={}):
+ def create(self, cr, uid, vals, context=None):
+ context = context or {}
if 'line_id' in vals and context.get('copy'):
for l in vals['line_id']:
if not l[0]:
return result
def copy(self, cr, uid, id, default={}, context={}):
+ context = context or {}
default.update({
'state':'draft',
'name':'/',
})
return super(account_move, self).copy(cr, uid, id, default, context)
- def unlink(self, cr, uid, ids, context={}, check=True):
+ def unlink(self, cr, uid, ids, context=None, check=True):
+ context = context or {}
toremove = []
+ obj_move_line = self.pool.get('account.move.line')
for move in self.browse(cr, uid, ids, context):
if move['state'] != 'draft':
raise osv.except_osv(_('UserError'),
line_ids = map(lambda x: x.id, move.line_id)
context['journal_id'] = move.journal_id.id
context['period_id'] = move.period_id.id
- self.pool.get('account.move.line')._update_check(cr, uid, line_ids, context)
- self.pool.get('account.move.line').unlink(cr, uid, line_ids, context=context)
+ obj_move_line._update_check(cr, uid, line_ids, context)
+ obj_move_line.unlink(cr, uid, line_ids, context=context)
toremove.append(move.id)
result = super(account_move, self).unlink(cr, uid, toremove, context)
return result
del context['__last_update']
valid_moves = [] #Maintains a list of moves which can be responsible to create analytic entries
-
+ obj_analytic_line = self.pool.get('account.analytic.line')
+ obj_move_line = self.pool.get('account.move.line')
for move in self.browse(cr, uid, ids, context):
# Unlink old analytic lines on move_lines
for obj_line in move.line_id:
for obj in obj_line.analytic_lines:
- self.pool.get('account.analytic.line').unlink(cr,uid,obj.id)
+ obj_analytic_line.unlink(cr,uid,obj.id)
journal = move.journal_id
amount = 0
if line.account_id.currency_id and line.currency_id:
if line.account_id.currency_id.id != line.currency_id.id and (line.account_id.currency_id.id != line.account_id.company_id.currency_id.id):
- raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""" % (line.account_id.code, line.account_id.name)))
+ raise osv.except_osv(_('Error'), _("""Couldn't create move with currency different from the secondary currency of the account "%s - %s". Clear the secondary currency field of the account definition if you want to accept all currencies.""") % (line.account_id.code, line.account_id.name))
if abs(amount) < 10 ** -4:
# If the move is balanced
# Check whether the move lines are confirmed
- if not len(line_draft_ids):
+ if not line_draft_ids:
continue
# Update the move lines (set them as valid)
- self.pool.get('account.move.line').write(cr, uid, line_draft_ids, {
+ obj_move_line.write(cr, uid, line_draft_ids, {
'journal_id': move.journal_id.id,
'period_id': move.period_id.id,
'state': 'valid'
code = account[line.account_id.id][0]
amount = account[line.account_id.id][1] * (line.debit + line.credit)
if (code or amount) and not (line.tax_code_id or line.tax_amount):
- self.pool.get('account.move.line').write(cr, uid, [line.id], {
+ obj_move_line.write(cr, uid, [line.id], {
'tax_code_id': code,
'tax_amount': amount
}, context, check=False)
#
self._centralise(cr, uid, move, 'debit', context=context)
self._centralise(cr, uid, move, 'credit', context=context)
- self.pool.get('account.move.line').write(cr, uid, line_draft_ids, {
+ obj_move_line.write(cr, uid, line_draft_ids, {
'state': 'valid'
}, context, check=False)
else:
# We can't validate it (it's unbalanced)
# Setting the lines as draft
- self.pool.get('account.move.line').write(cr, uid, line_ids, {
+ obj_move_line.write(cr, uid, line_ids, {
'journal_id': move.journal_id.id,
'period_id': move.period_id.id,
'state': 'draft'
}, context, check=False)
# Create analytic lines for the valid moves
for record in valid_moves:
- self.pool.get('account.move.line').create_analytic_lines(cr, uid, [line.id for line in record.line_id], context)
+ obj_move_line.create_analytic_lines(cr, uid, [line.id for line in record.line_id], context)
valid_moves = [move.id for move in valid_moves]
return len(valid_moves) > 0 and valid_moves or False
return True
def name_get(self, cr, uid, ids, context=None):
- if not len(ids):
+ if not ids:
return []
result = []
for r in self.browse(cr, uid, ids, context):
GROUP BY line.tax_code_id',
(parent_ids,) + where_params)
res=dict(cr.fetchall())
+ obj_precision = self.pool.get('decimal.precision')
for record in self.browse(cr, uid, ids, context):
def _rec_get(record):
amount = res.get(record.id, 0.0)
for rec in record.child_ids:
amount += _rec_get(rec) * rec.sign
return amount
- res[record.id] = round(_rec_get(record), self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
+ res[record.id] = round(_rec_get(record), obj_precision.precision_get(cr, uid, 'Account'))
return res
def _sum_year(self, cr, uid, ids, name, args, context=None):
if context is None:
context = {}
move_state = ('posted', )
- if context.get('state', False) == 'all':
+ if context.get('state', 'all') == 'all':
move_state = ('draft', 'posted', )
if context.get('fiscalyear_id', False):
fiscalyear_id = context['fiscalyear_id']
period_id = context['period_id']
else:
period_id = self.pool.get('account.period').find(cr, uid)
- if not len(period_id):
+ if not period_id:
return dict.fromkeys(ids, 0.0)
period_id = period_id[0]
return self._sum(cr, uid, ids, name, args, context,
'notprintable':fields.boolean("Not Printable in Invoice", help="Check this box if you don't want any VAT related to this Tax Code to appear on invoices"),
}
-
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
if not args:
args = []
def name_get(self, cr, uid, ids, context=None):
- if not len(ids):
+ if isinstance(ids, (int, long)):
+ ids = [ids]
+ if not ids:
return []
if isinstance(ids, (int, long)):
ids = [ids]
reads = self.read(cr, uid, ids, ['name','code'], context, load='_classic_write')
- return [(x['id'], (x['code'] and x['code'] + ' - ' or '') + x['name']) \
+ return [(x['id'], (x['code'] and (x['code'] + ' - ') or '') + x['name']) \
for x in reads]
def _default_company(self, cr, uid, context={}):
_constraints = [
(_check_recursion, 'Error ! You can not create recursive accounts.', ['parent_id'])
]
- _order = 'code,name'
+ _order = 'code'
account_tax_code()
class account_tax(osv.osv):
return result in the context
Ex: result=round(price_unit*0.21,4)
"""
+
+ def get_precision_tax():
+ def change_digit_tax(cr):
+ res = pooler.get_pool(cr.dbname).get('decimal.precision').precision_get(cr, 1, 'Account')
+ return (16, res+2)
+ return change_digit_tax
+
_name = 'account.tax'
_description = 'Tax'
_columns = {
'name': fields.char('Tax Name', size=64, required=True, translate=True, help="This name will be displayed on reports"),
'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the tax lines from the lowest sequences to the higher ones. The order is important if you have a tax with several tax children. In this case, the evaluation order is important."),
- 'amount': fields.float('Amount', required=True, digits=(14,4), help="For Tax Type percent enter % ratio between 0-1."),
+ 'amount': fields.float('Amount', required=True, digits_compute=get_precision_tax(), help="For taxes of type percentage, enter % ratio between 0-1."),
'active': fields.boolean('Active', help="If the active field is set to true, it will allow you to hide the tax without removing it."),
- 'type': fields.selection( [('percent','Percent'), ('fixed','Fixed'), ('none','None'), ('code','Python Code'),('balance','Balance')], 'Tax Type', required=True,
+ 'type': fields.selection( [('percent','Percentage'), ('fixed','Fixed Amount'), ('none','None'), ('code','Python Code'), ('balance','Balance')], 'Tax Type', required=True,
help="The computation method for the tax amount."),
- 'applicable_type': fields.selection( [('true','True'), ('code','Python Code')], 'Applicable Type', required=True,
+ 'applicable_type': fields.selection( [('true','Always'), ('code','Given by Python Code')], 'Applicability', required=True,
help="If not applicable (computed through a Python code), the tax won't appear on the invoice."),
'domain':fields.char('Domain', size=32, help="This field is only used if you develop your own module allowing developers to create specific taxes in a custom domain."),
'account_collected_id':fields.many2one('account.account', 'Invoice Tax Account'),
'python_compute':fields.text('Python Code'),
'python_compute_inv':fields.text('Python Code (reverse)'),
'python_applicable':fields.text('Python Code'),
- 'tax_group': fields.selection([('vat','VAT'),('other','Other')], 'Tax Group', help="If a default tax is given in the partner it only overrides taxes from accounts (or products) in the same group."),
#
# Fields used for the VAT declaration
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=80):
"""
Returns a list of tupples containing id, name, as internally it is called {def name_get}
- result format : {[(id, name), (id, name), ...]}
+ result format: {[(id, name), (id, name), ...]}
@param cr: A database cursor
@param user: ID of the user currently logged in
ids = self.search(cr, user, args, limit=limit, context=context)
return self.name_get(cr, user, ids, context=context)
+ def write(self, cr, uid, ids, vals, context=None):
+ if vals.get('type', False) and vals['type'] in ('none', 'code'):
+ vals.update({'amount': 0.0})
+ return super(account_tax, self).write(cr, uid, ids, vals, context=context)
+
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
journal_pool = self.pool.get('account.journal')
return super(account_tax, self).search(cr, uid, args, offset, limit, order, context, count)
def name_get(self, cr, uid, ids, context=None):
- if not len(ids):
+ if not ids:
return []
res = []
for record in self.read(cr, uid, ids, ['description','name'], context=context):
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
_defaults = {
- 'python_compute': '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or None\n# partner : res.partner object or None\n\nresult = price_unit * 0.10''',
- 'python_compute_inv': '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or False\n\nresult = price_unit * 0.10''',
+ 'python_compute': '''# price_unit\n# address: res.partner.address object or False\n# product: product.product object or None\n# partner: res.partner object or None\n\nresult = price_unit * 0.10''',
+ 'python_compute_inv': '''# price_unit\n# address: res.partner.address object or False\n# product: product.product object or False\n\nresult = price_unit * 0.10''',
'applicable_type': 'true',
'type': 'percent',
'amount': 0,
'active': 1,
'type_tax_use': 'all',
'sequence': 1,
- 'tax_group': 'vat',
'ref_tax_sign': 1,
'ref_base_sign': 1,
'tax_sign': 1,
def _applicable(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None):
res = []
+ obj_partener_address = self.pool.get('res.partner.address')
for tax in taxes:
if tax.applicable_type=='code':
- localdict = {'price_unit':price_unit, 'address':self.pool.get('res.partner.address').browse(cr, uid, address_id), 'product':product, 'partner':partner}
+ localdict = {'price_unit':price_unit, 'address':obj_partener_address.browse(cr, uid, address_id), 'product':product, 'partner':partner}
exec tax.python_applicable in localdict
if localdict.get('result', False):
res.append(tax)
def _unit_compute(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None, quantity=0):
taxes = self._applicable(cr, uid, taxes, price_unit, address_id, product, partner)
-
res = []
cur_price_unit=price_unit
+ obj_partener_address = self.pool.get('res.partner.address')
for tax in taxes:
# we compute the amount for the current tax object and append it to the result
data = {'id':tax.id,
- 'name':tax.description and tax.description + " - " + tax.name or tax.name,
- 'account_collected_id':tax.account_collected_id.id,
- 'account_paid_id':tax.account_paid_id.id,
- 'base_code_id': tax.base_code_id.id,
- 'ref_base_code_id': tax.ref_base_code_id.id,
- 'sequence': tax.sequence,
- 'base_sign': tax.base_sign,
- 'tax_sign': tax.tax_sign,
- 'ref_base_sign': tax.ref_base_sign,
- 'ref_tax_sign': tax.ref_tax_sign,
- 'price_unit': cur_price_unit,
- 'tax_code_id': tax.tax_code_id.id,
- 'ref_tax_code_id': tax.ref_tax_code_id.id,
+ 'name':tax.description and tax.description + " - " + tax.name or tax.name,
+ 'account_collected_id':tax.account_collected_id.id,
+ 'account_paid_id':tax.account_paid_id.id,
+ 'base_code_id': tax.base_code_id.id,
+ 'ref_base_code_id': tax.ref_base_code_id.id,
+ 'sequence': tax.sequence,
+ 'base_sign': tax.base_sign,
+ 'tax_sign': tax.tax_sign,
+ 'ref_base_sign': tax.ref_base_sign,
+ 'ref_tax_sign': tax.ref_tax_sign,
+ 'price_unit': cur_price_unit,
+ 'tax_code_id': tax.tax_code_id.id,
+ 'ref_tax_code_id': tax.ref_tax_code_id.id,
}
res.append(data)
if tax.type=='percent':
data['tax_amount']=quantity
# data['amount'] = quantity
elif tax.type=='code':
- address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
+ address = address_id and obj_partener_address.browse(cr, uid, address_id) or None
localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner}
exec tax.python_compute in localdict
amount = localdict['result']
data['amount'] = cur_price_unit - reduce(lambda x,y: y.get('amount',0.0)+x, res, 0.0)
data['balance'] = cur_price_unit
- amount2 = data['amount']
- if len(tax.child_ids):
+ amount2 = data.get('amount', 0.0)
+ if tax.child_ids:
if tax.child_depend:
latest = res.pop()
amount = amount2
tex.append(tax)
tin = self.compute_inv(cr, uid, tin, price_unit, quantity, address_id=address_id, product=product, partner=partner)
for r in tin:
- totalex -= r['amount']
+ totalex -= r.get('amount', 0.0)
totlex_qty = 0.0
try:
totlex_qty=totalex/quantity
pass
tex = self._compute(cr, uid, tex, totlex_qty, quantity, address_id=address_id, product=product, partner=partner)
for r in tex:
- totalin += r['amount']
+ totalin += r.get('amount', 0.0)
return {
'total': totalex,
'total_included': totalin,
"""
res = self._unit_compute(cr, uid, taxes, price_unit, address_id, product, partner, quantity)
total = 0.0
+ precision_pool = self.pool.get('decimal.precision')
for r in res:
if r.get('balance',False):
- r['amount'] = round(r['balance'] * quantity, self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')) - total
+ r['amount'] = round(r.get('balance', 0.0) * quantity, precision_pool.precision_get(cr, uid, 'Account')) - total
else:
- r['amount'] = round(r['amount'] * quantity, self.pool.get('decimal.precision').precision_get(cr, uid, 'Account'))
+ r['amount'] = round(r.get('amount', 0.0) * quantity, precision_pool.precision_get(cr, uid, 'Account'))
total += r['amount']
return res
def _unit_compute_inv(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None):
taxes = self._applicable(cr, uid, taxes, price_unit, address_id, product, partner)
-
+ obj_partener_address = self.pool.get('res.partner.address')
res = []
taxes.reverse()
cur_price_unit = price_unit
amount = tax.amount
elif tax.type=='code':
- address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
+ address = address_id and obj_partener_address.browse(cr, uid, address_id) or None
localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner}
exec tax.python_compute_inv in localdict
amount = localdict['result']
'tax_code_id': tax.tax_code_id.id,
'ref_tax_code_id': tax.ref_tax_code_id.id,
})
- if len(tax.child_ids):
+ if tax.child_ids:
if tax.child_depend:
del res[-1]
amount = price_unit
"""
res = self._unit_compute_inv(cr, uid, taxes, price_unit, address_id, product, partner=None)
total = 0.0
+ obj_precision = self.pool.get('decimal.precision')
for r in res:
- prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
+ prec = obj_precision.precision_get(cr, uid, 'Account')
if r.get('balance',False):
r['amount'] = round(r['balance'] * quantity, prec) - total
else:
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True),
'lines_id': fields.one2many('account.model.line', 'model_id', 'Model Entries'),
- 'legend' :fields.text('Legend', readonly=True, size=100),
+ 'legend': fields.text('Legend', readonly=True, size=100),
}
_defaults = {
- 'legend': lambda self, cr, uid, context:_('You can specify year, month and date in the name of the model using the following labels:\n\n%(year)s : To Specify Year \n%(month)s : To Specify Month \n%(date)s : Current Date\n\ne.g. My model on %(date)s'),
+ 'legend': lambda self, cr, uid, context:_('You can specify year, month and date in the name of the model using the following labels:\n\n%(year)s: To Specify Year \n%(month)s: To Specify Month \n%(date)s: Current Date\n\ne.g. My model on %(date)s'),
}
def generate(self, cr, uid, ids, datas={}, context=None):
move_ids = []
date_maturity = time.strftime('%Y-%m-%d')
if line.date_maturity == 'partner':
if not line.partner_id:
- raise osv.except_osv(_('Error !'), _("Maturity date of entry line generated by model line '%s' of model '%s' is based on partner payment term! \
- \nPlease define partner on it!"%(line.name, model.name)))
+ raise osv.except_osv(_('Error !'), _("Maturity date of entry line generated by model line '%s' of model '%s' is based on partner payment term!" \
+ "\nPlease define partner on it!")%(line.name, model.name))
if line.partner_id.property_payment_term:
payment_term_id = line.partner_id.property_payment_term.id
pterm_list = pt_obj.compute(cr, uid, payment_term_id, value=1, date_ref=date_maturity)
'lines_id': fields.one2many('account.subscription.line', 'subscription_id', 'Subscription Lines')
}
_defaults = {
- 'date_start': time.strftime('%Y-%m-%d'),
+ 'date_start': lambda *a: time.strftime('%Y-%m-%d'),
'period_type': 'month',
'period_total': 12,
'period_nbr': 1,
break
if ok:
todone.append(sub.id)
- if len(todone):
+ if todone:
self.write(cr, uid, todone, {'state':'done'})
return False
for line in sub.lines_id:
if not line.move_id.id:
toremove.append(line.id)
- if len(toremove):
+ if toremove:
self.pool.get('account.subscription.line').unlink(cr, uid, toremove)
self.write(cr, uid, ids, {'state':'draft'})
return False
def move_create(self, cr, uid, ids, context=None):
tocheck = {}
all_moves = []
+ obj_model = self.pool.get('account.model')
for line in self.browse(cr, uid, ids, context=context):
datas = {
'date': line.date,
}
- move_ids = self.pool.get('account.model').generate(cr, uid, [line.subscription_id.model_id.id], datas, context)
+ move_ids = obj_model.generate(cr, uid, [line.subscription_id.model_id.id], datas, context)
tocheck[line.subscription_id.id] = True
self.write(cr, uid, [line.id], {'move_id':move_ids[0]})
all_moves.extend(move_ids)
account_subscription_line()
# ---------------------------------------------------------------
-# Account Templates : Account, Tax, Tax Code and chart. + Wizard
+# Account Templates: Account, Tax, Tax Code and chart. + Wizard
# ---------------------------------------------------------------
class account_tax_template(osv.osv):
('view','View'),
('consolidation','Consolidation'),
('liquidity','Liquidity'),
- ('other','Others'),
+ ('other','Regular'),
('closed','Closed'),
], 'Internal Type', required=True,help="This type is used to differentiate types with "\
"special effects in OpenERP: view can not have entries, consolidation are accounts that "\
_defaults = {
'reconcile': False,
- 'type' : 'view',
+ 'type': 'view',
'nocreate': False,
}
def name_get(self, cr, uid, ids, context={}):
- if not len(ids):
+ if not ids:
return []
reads = self.read(cr, uid, ids, ['name','code'], context)
res = []
'parent_id': data[0]['cparent_id'],
'company_id': company_id,
}
- new_account = acc_obj.create(cr, uid, vals)
+ acc_obj.create(cr, uid, vals)
return {'type':'state', 'state': 'end' }
def action_cancel(self, cr, uid, ids, context=None):
'info': fields.text('Description'),
'parent_id': fields.many2one('account.tax.code.template', 'Parent Code', select=True),
'child_ids': fields.one2many('account.tax.code.template', 'parent_id', 'Child Codes'),
- 'sign': fields.float('Sign for parent', required=True),
+ 'sign': fields.float('Sign For Parent', required=True),
'notprintable':fields.boolean("Not Printable in Invoice", help="Check this box if you don't want any VAT related to this Tax Code to appear on invoices"),
}
}
def name_get(self, cr, uid, ids, context=None):
- if not len(ids):
+ if not ids:
return []
if isinstance(ids, (int, long)):
ids = [ids]
'property_account_income_categ': fields.many2one('account.account.template','Income Category Account'),
'property_account_expense': fields.many2one('account.account.template','Expense Account on Product Template'),
'property_account_income': fields.many2one('account.account.template','Income Account on Product Template'),
- 'property_reserve_and_surplus_account': fields.many2one('account.account.template', 'Reserve and Profit/Loss Account', domain=[('type', '=', 'payable')] , help='This Account is used for transferring Profit/Loss(If It is Profit : Amount will be added, Loss : Amount will be deducted.), Which is calculated from Profilt & Loss Report'),
+ 'property_reserve_and_surplus_account': fields.many2one('account.account.template', 'Reserve and Profit/Loss Account', domain=[('type', '=', 'payable')], help='This Account is used for transferring Profit/Loss(If It is Profit: Amount will be added, Loss: Amount will be deducted.), Which is calculated from Profilt & Loss Report'),
}
account_chart_template()
'python_compute':fields.text('Python Code'),
'python_compute_inv':fields.text('Python Code (reverse)'),
'python_applicable':fields.text('Python Code'),
- 'tax_group': fields.selection([('vat','VAT'),('other','Other')], 'Tax Group', help="If a default tax if given in the partner it only override taxes from account (or product) of the same group."),
#
# Fields used for the VAT declaration
}
def name_get(self, cr, uid, ids, context={}):
- if not len(ids):
+ if not ids:
return []
res = []
for record in self.read(cr, uid, ids, ['description','name'], context):
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
_defaults = {
- 'python_compute': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or None\n# partner : res.partner object or None\n\nresult = price_unit * 0.10''',
- 'python_compute_inv': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n# product : product.product object or False\n\nresult = price_unit * 0.10''',
+ 'python_compute': lambda *a: '''# price_unit\n# address: res.partner.address object or False\n# product: product.product object or None\n# partner: res.partner object or None\n\nresult = price_unit * 0.10''',
+ 'python_compute_inv': lambda *a: '''# price_unit\n# address: res.partner.address object or False\n# product: product.product object or False\n\nresult = price_unit * 0.10''',
'applicable_type': 'true',
'type': 'percent',
'amount': 0,
'sequence': 1,
- 'tax_group': 'vat',
'ref_tax_sign': 1,
'ref_base_sign': 1,
'tax_sign': 1,
account_tax_template()
-# Fiscal Mapping Templates
+# Fiscal Position Templates
class account_fiscal_position_template(osv.osv):
_name = 'account.fiscal.position.template'
- _description = 'Template for Fiscal Mapping'
+ _description = 'Template for Fiscal Position'
_columns = {
- 'name': fields.char('Fiscal Mapping Template', size=64, translate=True, required=True),
+ 'name': fields.char('Fiscal Position Template', size=64, translate=True, required=True),
'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True),
'account_ids': fields.one2many('account.fiscal.position.account.template', 'position_id', 'Account Mapping'),
'tax_ids': fields.one2many('account.fiscal.position.tax.template', 'position_id', 'Tax Mapping')
class account_fiscal_position_tax_template(osv.osv):
_name = 'account.fiscal.position.tax.template'
- _description = 'Template Tax Fiscal Mapping'
+ _description = 'Template Tax Fiscal Position'
_rec_name = 'position_id'
_columns = {
- 'position_id': fields.many2one('account.fiscal.position.template', 'Fiscal Mapping', required=True, ondelete='cascade'),
+ 'position_id': fields.many2one('account.fiscal.position.template', 'Fiscal Position', required=True, ondelete='cascade'),
'tax_src_id': fields.many2one('account.tax.template', 'Tax Source', required=True),
'tax_dest_id': fields.many2one('account.tax.template', 'Replacement Tax')
}
'bank_accounts_id': fields.one2many('account.bank.accounts.wizard', 'bank_account_id', 'Bank Accounts', required=True),
'code_digits':fields.integer('# of Digits', required=True, help="No. of Digits to use for account code"),
'seq_journal':fields.boolean('Separated Journal Sequences', help="Check this box if you want to use a different sequence for each created journal. Otherwise, all will use the same sequence."),
+ "sale_tax": fields.many2one("account.tax.template", "Default Sale Tax"),
+ "purchase_tax": fields.many2one("account.tax.template", "Default Purchase Tax"),
}
+ def onchange_chart_template_id(self, cr, uid, ids, chart_template_id=False, context=None):
+ res = {}
+ res['value'] = {}
+ res['value']["sale_tax"] = False
+ res['value']["purchase_tax"] = False
+ if chart_template_id:
+ sale_tax_ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id"
+ , "=", chart_template_id), ('type_tax_use', 'in', ('sale','all'))], order="sequence")
+ purchase_tax_ids = self.pool.get('account.tax.template').search(cr, uid, [("chart_template_id"
+ , "=", chart_template_id), ('type_tax_use', 'in', ('purchase','all'))], order="sequence")
+ res['value']["sale_tax"] = sale_tax_ids and sale_tax_ids[0] or False
+ res['value']["purchase_tax"] = purchase_tax_ids and purchase_tax_ids[0] or False
+ return res
def _get_chart(self, cr, uid, context={}):
ids = self.pool.get('account.chart.template').search(cr, uid, [], context=context)
if ids:
return ids[0]
return False
+
+ def _get_default_accounts(self, cr, uid, context=None):
+ accounts = [{'acc_name':'Current','account_type':'bank'},
+ {'acc_name':'Deposit','account_type':'bank'},
+ {'acc_name':'Cash','account_type':'cash'}]
+ return accounts
+
_defaults = {
'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr, uid, [uid], c)[0].company_id.id,
'chart_template_id': _get_chart,
+ 'bank_accounts_id': _get_default_accounts,
'code_digits': 6,
'seq_journal': True
}
obj_acc_template = self.pool.get('account.account.template')
obj_fiscal_position_template = self.pool.get('account.fiscal.position.template')
obj_fiscal_position = self.pool.get('account.fiscal.position')
- data_pool = self.pool.get('ir.model.data')
-
+ obj_data = self.pool.get('ir.model.data')
+ analytic_journal_obj = self.pool.get('account.analytic.journal')
+ obj_tax_code = self.pool.get('account.tax.code')
# Creating Account
obj_acc_root = obj_multi.chart_template_id.account_root_id
tax_code_root_id = obj_multi.chart_template_id.tax_code_root_id.id
'company_id': company_id,
'sign': tax_code_template.sign,
}
- new_tax_code = self.pool.get('account.tax.code').create(cr, uid, vals)
+ new_tax_code = obj_tax_code.create(cr, uid, vals)
#recording the new tax code to do the mapping
tax_code_template_ref[tax_code_template.id] = new_tax_code
#create all the tax
+ tax_template_to_tax = {}
for tax in obj_multi.chart_template_id.tax_template_ids:
#create it
vals_tax = {
'python_compute': tax.python_compute,
'python_compute_inv': tax.python_compute_inv,
'python_applicable': tax.python_applicable,
- 'tax_group':tax.tax_group,
'base_code_id': tax.base_code_id and ((tax.base_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.base_code_id.id]) or False,
'tax_code_id': tax.tax_code_id and ((tax.tax_code_id.id in tax_code_template_ref) and tax_code_template_ref[tax.tax_code_id.id]) or False,
'base_sign': tax.base_sign,
'type_tax_use': tax.type_tax_use
}
new_tax = obj_acc_tax.create(cr, uid, vals_tax)
+ tax_template_to_tax[tax.id] = new_tax
#as the accounts have not been created yet, we have to wait before filling these fields
todo_dict[new_tax] = {
'account_collected_id': tax.account_collected_id and tax.account_collected_id.id or False,
# Creating Journals Sales and Purchase
vals_journal={}
- data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')])
- data = data_pool.browse(cr, uid, data_id[0])
+ data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_sp_journal_view')])
+ data = obj_data.browse(cr, uid, data_id[0])
view_id = data.res_id
seq_id = obj_sequence.search(cr, uid, [('name','=','Account Journal')])[0]
if obj_multi.seq_journal:
seq_id_sale = obj_sequence.search(cr, uid, [('name','=','Sale Journal')])[0]
seq_id_purchase = obj_sequence.search(cr, uid, [('name','=','Purchase Journal')])[0]
+ seq_id_sale_refund = obj_sequence.search(cr, uid, [('name','=','Sales Refund Journal')])
+ if seq_id_sale_refund:
+ seq_id_sale_refund = seq_id_sale_refund[0]
+ seq_id_purchase_refund = obj_sequence.search(cr, uid, [('name','=','Purchase Refund Journal')])
+ if seq_id_purchase_refund:
+ seq_id_purchase_refund = seq_id_purchase_refund[0]
else:
seq_id_sale = seq_id
seq_id_purchase = seq_id
+ seq_id_sale_refund = seq_id
+ seq_id_purchase_refund = seq_id
vals_journal['view_id'] = view_id
#Sales Journal
+ analitical_sale_ids = analytic_journal_obj.search(cr,uid,[('type','=','sale')])
+ analitical_journal_sale = analitical_sale_ids and analitical_sale_ids[0] or False
+
vals_journal['name'] = _('Sales Journal')
vals_journal['type'] = 'sale'
vals_journal['code'] = _('SAJ')
vals_journal['sequence_id'] = seq_id_sale
vals_journal['company_id'] = company_id
+ vals_journal['analytic_journal_id'] = analitical_journal_sale
if obj_multi.chart_template_id.property_account_receivable:
vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id]
obj_journal.create(cr,uid,vals_journal)
# Purchase Journal
+ analitical_purchase_ids = analytic_journal_obj.search(cr,uid,[('type','=','purchase')])
+ analitical_journal_purchase = analitical_purchase_ids and analitical_purchase_ids[0] or False
+
vals_journal['name'] = _('Purchase Journal')
vals_journal['type'] = 'purchase'
vals_journal['code'] = _('EXJ')
vals_journal['sequence_id'] = seq_id_purchase
vals_journal['view_id'] = view_id
vals_journal['company_id'] = company_id
+ vals_journal['analytic_journal_id'] = analitical_journal_purchase
if obj_multi.chart_template_id.property_account_payable:
vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]
obj_journal.create(cr,uid,vals_journal)
+ # Creating Journals Sales Refund and Purchase Refund
+ vals_journal = {}
+ data_id = obj_data.search(cr, uid, [('model', '=', 'account.journal.view'), ('name', '=', 'account_sp_refund_journal_view')], context=context)
+ data = obj_data.browse(cr, uid, data_id[0], context=context)
+ view_id = data.res_id
+
+ #Sales Refund Journal
+ vals_journal = {
+ 'view_id': view_id,
+ 'name': _('Sales Refund Journal'),
+ 'type': 'sale_refund',
+ 'refund_journal': True,
+ 'code': _('SCNJ'),
+ 'sequence_id': seq_id_sale_refund,
+ 'analytic_journal_id': analitical_journal_sale,
+ 'company_id': company_id
+ }
+
+ if obj_multi.chart_template_id.property_account_receivable:
+ vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id]
+ vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id]
+
+
+# if obj_multi.property_account_receivable:
+# vals_journal.update({
+# 'default_credit_account_id': acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id],
+# 'default_debit_account_id': acc_template_ref[obj_multi.chart_template_id.property_account_income_categ.id]
+# })
+ obj_journal.create(cr, uid, vals_journal, context=context)
+
+ # Purchase Refund Journal
+ vals_journal = {
+ 'view_id': view_id,
+ 'name': _('Purchase Refund Journal'),
+ 'type': 'purchase_refund',
+ 'refund_journal': True,
+ 'code': _('ECNJ'),
+ 'sequence_id': seq_id_purchase_refund,
+ 'analytic_journal_id': analitical_journal_purchase,
+ 'company_id': company_id
+ }
+
+ if obj_multi.chart_template_id.property_account_payable:
+ vals_journal['default_credit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]
+ vals_journal['default_debit_account_id'] = acc_template_ref[obj_multi.chart_template_id.property_account_expense_categ.id]
+
+
+# if obj_multi.property_account_payable:
+# vals_journal.update({
+# 'default_credit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id],
+# 'default_debit_account_id': acc_template_ref[obj_multi.property_account_expense_categ.id]
+# })
+ obj_journal.create(cr, uid, vals_journal, context=context)
+
# Bank Journals
- data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view')])
- data = data_pool.browse(cr, uid, data_id[0])
+ data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view')])
+ data = obj_data.browse(cr, uid, data_id[0])
view_id_cash = data.res_id
- data_id = data_pool.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view_multi')])
- data = data_pool.browse(cr, uid, data_id[0])
+ data_id = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view_multi')])
+ data = obj_data.browse(cr, uid, data_id[0])
view_id_cur = data.res_id
ref_acc_bank = obj_multi.chart_template_id.bank_account_view_id
if ref_acc_bank.code:
try:
new_code = str(int(ref_acc_bank.code.ljust(dig,'0')) + current_num)
- except Exception,e:
+ except:
new_code = str(ref_acc_bank.code.ljust(dig-len(str(current_num)),'0')) + str(current_num)
vals = {
'name': tmp,
seq_id = obj_sequence.create(cr,uid,vals_seq)
#create the bank journal
+ analitical_bank_ids = analytic_journal_obj.search(cr,uid,[('type','=','situation')])
+ analitical_journal_bank = analitical_bank_ids and analitical_bank_ids[0] or False
+
vals_journal['name']= vals['name']
vals_journal['code']= _('BNK') + str(current_num)
vals_journal['sequence_id'] = seq_id
vals_journal['type'] = 'cash'
vals_journal['company_id'] = company_id
+ vals_journal['analytic_journal_id'] = analitical_journal_bank
if line.currency_id:
vals_journal['view_id'] = view_id_cur
vals_journal['view_id'] = view_id_cash
vals_journal['default_credit_account_id'] = acc_cash_id
vals_journal['default_debit_account_id'] = acc_cash_id
- obj_journal.create(cr,uid,vals_journal)
-
+ obj_journal.create(cr, uid, vals_journal)
current_num += 1
#create the properties
fp_ids = obj_fiscal_position_template.search(cr, uid, [('chart_template_id', '=', obj_multi.chart_template_id.id)])
if fp_ids:
+
+ obj_tax_fp = self.pool.get('account.fiscal.position.tax')
+ obj_ac_fp = self.pool.get('account.fiscal.position.account')
+
for position in obj_fiscal_position_template.browse(cr, uid, fp_ids):
vals_fp = {
- 'company_id' : company_id,
- 'name' : position.name,
+ 'company_id': company_id,
+ 'name': position.name,
}
new_fp = obj_fiscal_position.create(cr, uid, vals_fp)
- obj_tax_fp = self.pool.get('account.fiscal.position.tax')
- obj_ac_fp = self.pool.get('account.fiscal.position.account')
-
for tax in position.tax_ids:
vals_tax = {
- 'tax_src_id' : tax_template_ref[tax.tax_src_id.id],
- 'tax_dest_id' : tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
- 'position_id' : new_fp,
+ 'tax_src_id': tax_template_ref[tax.tax_src_id.id],
+ 'tax_dest_id': tax.tax_dest_id and tax_template_ref[tax.tax_dest_id.id] or False,
+ 'position_id': new_fp,
}
obj_tax_fp.create(cr, uid, vals_tax)
for acc in position.account_ids:
vals_acc = {
- 'account_src_id' : acc_template_ref[acc.account_src_id.id],
- 'account_dest_id' : acc_template_ref[acc.account_dest_id.id],
- 'position_id' : new_fp,
+ 'account_src_id': acc_template_ref[acc.account_src_id.id],
+ 'account_dest_id': acc_template_ref[acc.account_dest_id.id],
+ 'position_id': new_fp,
}
obj_ac_fp.create(cr, uid, vals_acc)
+
+ ir_values = self.pool.get('ir.values')
+ if obj_multi.sale_tax:
+ ir_values.set(cr, uid, key='default', key2=False, name="taxes_id", company=obj_multi.company_id.id,
+ models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.sale_tax.id]])
+ if obj_multi.purchase_tax:
+ ir_values.set(cr, uid, key='default', key2=False, name="supplier_taxes_id", company=obj_multi.company_id.id,
+ models =[('product.product',False)], value=[tax_template_to_tax[obj_multi.purchase_tax.id]])
+
wizard_multi_charts_accounts()
class account_bank_accounts_wizard(osv.osv_memory):
- _name='account.bank.accounts.wizard'
+ _name = 'account.bank.accounts.wizard'
_columns = {
- 'acc_name':fields.char('Account Name.', size=64, required=True),
- 'bank_account_id':fields.many2one('wizard.multi.charts.accounts', 'Bank Account', required=True),
- 'currency_id':fields.many2one('res.currency', 'Currency'),
- 'account_type':fields.selection([('cash','Cash'),('check','Check'),('bank','Bank')], 'Type', size=32),
+ 'acc_name': fields.char('Account Name.', size=64, required=True),
+ 'bank_account_id': fields.many2one('wizard.multi.charts.accounts', 'Bank Account', required=True),
+ 'currency_id': fields.many2one('res.currency', 'Currency'),
+ 'account_type': fields.selection([('cash','Cash'),('check','Check'),('bank','Bank')], 'Type', size=32),
}
_defaults = {
'currency_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.currency_id.id,
- }
+ }
account_bank_accounts_wizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
-