diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py
index da1f95de301..c432689de44 100644
--- a/addons/account/__openerp__.py
+++ b/addons/account/__openerp__.py
@@ -95,7 +95,6 @@ module named account_voucher.
'account_invoice_workflow.xml',
'project/project_view.xml',
'project/project_report.xml',
- 'project/wizard/account_analytic_check_view.xml',
'project/wizard/account_analytic_balance_report_view.xml',
'project/wizard/account_analytic_cost_ledger_view.xml',
'project/wizard/account_analytic_inverted_balance_report.xml',
diff --git a/addons/account/account.py b/addons/account/account.py
index 08725e0cc5e..b1c19476548 100644
--- a/addons/account/account.py
+++ b/addons/account/account.py
@@ -109,10 +109,8 @@ class account_payment_term_line(osv.osv):
'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the payment term lines from the lowest sequences to the higher ones"),
'value': fields.selection([('procent', 'Percent'),
('balance', 'Balance'),
- ('fixed', 'Fixed Amount')], 'Value',
- required=True, help="""Example: 14 days 2%, 30 days net
-1. Line 1: percent 0.02 14 days
-2. Line 2: balance 30 days"""),
+ ('fixed', 'Fixed Amount')], 'Valuation',
+ required=True, help="""Select here the kind of valuation related to this payment term line. Note that you should have your last line with the type 'Balance' to ensure that the whole amount will be threated."""),
'value_amount': fields.float('Value Amount', help="For Value percent enter % ratio between 0-1."),
'days': fields.integer('Number of Days', required=True, help="Number of days to add before computation of the day of month." \
@@ -145,8 +143,12 @@ class account_account_type(osv.osv):
_columns = {
'name': fields.char('Acc. Type Name', size=64, required=True, translate=True),
'code': fields.char('Code', size=32, required=True),
- 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of account types."),
- 'close_method': fields.selection([('none', 'None'), ('balance', 'Balance'), ('detail', 'Detail'), ('unreconciled', 'Unreconciled')], 'Deferral Method', required=True),
+ 'close_method': fields.selection([('none', 'None'), ('balance', 'Balance'), ('detail', 'Detail'), ('unreconciled', 'Unreconciled')], 'Deferral Method', required=True, help="""Set here the method that will be used to generate the end of year journal entries for all the accounts of this type.
+
+ 'None' means that nothing will be done.
+ 'Balance' will generally be used for cash accounts.
+ 'Detail' will copy each existing journal item of the previous year, even the reconciled ones.
+ 'Unreconciled' will copy only the journal items that were unreconciled on the first day of the new fiscal year."""),
'sign': fields.selection([(-1, 'Negative'), (1, 'Positive')], 'Sign on Reports', required=True, help='Allows you to change the sign of the balance amount displayed in the reports, so that you can see positive figures instead of negative ones in expenses accounts.'),
'report_type':fields.selection([
('none','/'),
@@ -160,11 +162,10 @@ class account_account_type(osv.osv):
'note': fields.text('Description'),
}
_defaults = {
- 'close_method': lambda *a: 'none',
- 'sequence': lambda *a: 5,
- 'sign': lambda *a: 1,
+ 'close_method': 'none',
+ 'sign': 1,
}
- _order = "sequence"
+ _order = "code"
def _check_recursion(self, cr, uid, ids):
#TODO: Need to check for recusrion
@@ -368,6 +369,7 @@ class account_account(osv.osv):
('other', 'Regular'),
('receivable', 'Receivable'),
('payable', 'Payable'),
+ ('liquidity','Liquidity'),
('consolidation', 'Consolidation'),
('closed', 'Closed'),
], 'Internal Type', required=True, help="This type is used to differentiate types with "\
@@ -465,6 +467,8 @@ class account_account(osv.osv):
ids = self.search(cr, user, [('shortcut', '=', name)]+ args, limit=limit)
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)
else:
ids = self.search(cr, user, args, context=context, limit=limit)
return self.name_get(cr, user, ids, context=context)
@@ -596,9 +600,9 @@ class account_journal(osv.osv):
_name = "account.journal"
_description = "Journal"
_columns = {
- 'name': fields.char('Journal Name', size=64, required=True, translate=True,help="Name of the journal"),
- 'code': fields.char('Code', size=16,required=True,help="Code of the journal"),
- 'type': fields.selection([('sale', 'Sale'),('sale_refund','Sale Refund'), ('purchase', 'Purchase'), ('purchase_refund','Purchase Refund'),('expense', 'Expense'), ('cash', 'Cash'), ('bank', 'Bank and Cheques'), ('general', 'General'), ('situation', 'Situation')], 'Type', size=32, required=True,
+ '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,
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."\
@@ -613,14 +617,12 @@ class account_journal(osv.osv):
'centralisation': fields.boolean('Centralised counterpart', help="Check this box to determine that each entry of this journal won't create a new counterpart but will share the same counterpart. This is used in fiscal year closing."),
'update_posted': fields.boolean('Allow Cancelling Entries', help="Check this box if you want to allow the cancellation the entries related to this journal or of the invoice related to this journal"),
'group_invoice_lines': fields.boolean('Group Invoice Lines', help="If this box is checked, the system will try to group the accounting lines when generating them from invoices."),
- 'sequence_id': fields.many2one('ir.sequence', 'Entry Sequence', help="The sequence gives the display order for a list of journals", required=False),
+ 'sequence_id': fields.many2one('ir.sequence', 'Entry Sequence', help="This field contains the informatin related to the numbering of the journal entries of this journal.", required=True),
'user_id': fields.many2one('res.users', 'User', help="The user responsible for this journal"),
'groups_id': fields.many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', 'Groups'),
'currency': fields.many2one('res.currency', 'Currency', help='The currency used to enter statement'),
'entry_posted': fields.boolean('Skip \'Draft\' State for Manual Entries', help='Check this box if you don\'t want new journal entries to pass through the \'draft\' state and instead goes directly to the \'posted state\' without any manual validation. \nNote that journal entries that are automatically created by the system are always skipping that state.'),
'company_id': fields.many2one('res.company', 'Company', required=True, select=1, help="Company related to this journal"),
-# 'invoice_sequence_id': fields.many2one('ir.sequence', 'Invoice Sequence', \
-# help="The sequence used for invoice numbers in this journal."),
'allow_date':fields.boolean('Check Date not in the Period', help= 'If set to True then do not accept the entry if the entry date is not into the period dates'),
}
@@ -637,7 +639,7 @@ class account_journal(osv.osv):
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, ids, context={}):
+ def create_sequence(self, cr, uid, vals, context={}):
"""
Create new entry sequence for every new Joural
@param cr: cursor to database
@@ -660,39 +662,29 @@ class account_journal(osv.osv):
date_pool = self.pool.get('ir.model.data')
result = True
+ name = vals['name']
+ code = vals['code'].lower()
- journal = self.browse(cr, uid, ids[0], context)
- code = journal.code.lower()
types = {
- 'name':journal.name,
- 'code':code
+ 'name': name,
+ 'code': code
}
type_id = seq_typ_pool.create(cr, uid, types)
seq = {
- 'name':journal.name,
- 'code':code,
- 'active':True,
- 'prefix':journal.code + "/%(year)s/",
- 'padding':4,
- 'number_increment':1
+ 'name': name,
+ 'code': code,
+ 'active': True,
+ 'prefix': code + "/%(year)s/",
+ 'padding': 4,
+ 'number_increment': 1
}
- seq_id = seq_pool.create(cr, uid, seq)
-
- res = {}
- if not journal.sequence_id:
- res.update({
- 'sequence_id':seq_id
- })
-
- result = self.write(cr, uid, [journal.id], res)
-
- return result
+ return seq_pool.create(cr, uid, seq)
def create(self, cr, uid, vals, context={}):
- journal_id = super(account_journal, self).create(cr, uid, vals, context)
- self.create_sequence(cr, uid, [journal_id], context)
- return journal_id
+ if not 'sequence_id' in vals or not vals['sequence_id']:
+ vals.update({'sequence_id' : self.create_sequence(cr, uid, vals, context)})
+ return super(account_journal, self).create(cr, uid, vals, context)
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
if not args:
@@ -718,7 +710,6 @@ class account_journal(osv.osv):
'sale_refund':'account_sp_refund_journal_view',
'purchase':'account_sp_journal_view',
'purchase_refund':'account_sp_refund_journal_view',
- 'expense':'account_sp_journal_view',
'cash':'account_journal_bank_view',
'bank':'account_journal_bank_view',
'general':'account_journal_view',
@@ -760,19 +751,34 @@ class account_fiscalyear(osv.osv):
'state': fields.selection([('draft','Open'), ('done','Closed')], 'State', readonly=True),
}
_defaults = {
- 'state': lambda *a: 'draft',
+ 'state': 'draft',
'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
}
_order = "date_start"
+ def _check_fiscal_year(self, cr, uid, ids, context=None):
+ current_fiscal_yr = self.browse(cr, uid, ids, context=context)[0]
+ obj_fiscal_ids = self.search(cr, uid, [('company_id', '=', current_fiscal_yr.company_id.id)], context=context)
+ obj_fiscal_ids.remove(ids[0])
+ data_fiscal_yr = self.browse(cr, uid, obj_fiscal_ids, context=context)
+
+ for old_fy in data_fiscal_yr:
+ if old_fy.company_id.id == current_fiscal_yr['company_id'].id:
+ # Condition to check if the current fiscal year falls in between any previously defined fiscal year
+ if old_fy.date_start <= current_fiscal_yr['date_start'] <= old_fy.date_stop or \
+ old_fy.date_start <= current_fiscal_yr['date_stop'] <= old_fy.date_stop:
+ return False
+ return True
+
def _check_duration(self,cr,uid,ids):
- obj_fy=self.browse(cr,uid,ids[0])
+ obj_fy = self.browse(cr,uid,ids[0])
if obj_fy.date_stop < obj_fy.date_start:
return False
return True
_constraints = [
- (_check_duration, 'Error ! The duration of the Fiscal Year is invalid. ', ['date_stop'])
+ (_check_duration, 'Error! The duration of the Fiscal Year is invalid. ', ['date_stop']),
+ (_check_fiscal_year, 'Error! You cannot define overlapping fiscal years',['date_start', 'date_stop'])
]
def create_period3(self,cr, uid, ids, context={}):
@@ -964,8 +970,8 @@ class account_journal_period(osv.osv):
return super(account_journal_period, self).unlink(cr, uid, ids, context)
_defaults = {
- 'state': lambda *a: 'draft',
- 'active': lambda *a: True,
+ 'state': 'draft',
+ 'active': True,
}
_order = "period_id"
@@ -978,6 +984,13 @@ class account_fiscalyear(osv.osv):
'end_journal_period_id':fields.many2one('account.journal.period','End of Year Entries Journal', readonly=True),
}
+ def copy(self, cr, uid, id, default={}, context=None):
+ default.update({
+ 'period_ids': [],
+ 'end_journal_period_id': False
+ })
+ return super(account_fiscalyear, self).copy(cr, uid, id, default=default, context=context)
+
account_fiscalyear()
#----------------------------------------------------------
# Entries
@@ -1075,8 +1088,8 @@ class account_move(osv.osv):
'ref': fields.char('Reference', size=64),
'period_id': fields.many2one('account.period', 'Period', required=True, states={'posted':[('readonly',True)]}),
'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'posted':[('readonly',True)]}),
- 'state': fields.selection([('draft','Draft'), ('posted','Posted')], 'State', required=True, readonly=True,
- help='When new account move is created the state will be \'Draft\'. When all the payments are done it will be in \'Posted\' state.'),
+ 'state': fields.selection([('draft','Unposted'), ('posted','Posted')], 'State', required=True, readonly=True,
+ 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"),
@@ -1086,10 +1099,10 @@ class account_move(osv.osv):
'company_id': fields.related('journal_id','company_id',type='many2one',relation='res.company',string='Company',store=True),
}
_defaults = {
- 'name': lambda *a: '/',
- 'state': lambda *a: 'draft',
+ 'name': '/',
+ 'state': 'draft',
'period_id': _get_period,
- 'date': lambda *a:time.strftime('%Y-%m-%d'),
+ 'date': 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,
}
@@ -1124,8 +1137,9 @@ class account_move(osv.osv):
def post(self, cr, uid, ids, context=None):
invoice = context.get('invoice', False)
- if self.validate(cr, uid, ids, context) and len(ids):
- for move in self.browse(cr, uid, ids):
+ 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
@@ -1145,7 +1159,7 @@ class account_move(osv.osv):
cr.execute('UPDATE account_move '\
'SET state=%s '\
'WHERE id IN %s',
- ('posted', tuple(ids),))
+ ('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
@@ -1342,8 +1356,8 @@ class account_move(osv.osv):
if not company_id == line.account_id.company_id.id:
raise osv.except_osv(_('Error'), _("Couldn't create move between different companies"))
- if line.account_id.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 or line.currency_id):
+ 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)))
if abs(amount) < 10 ** -4:
@@ -1409,7 +1423,8 @@ class account_move(osv.osv):
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)
- return len(valid_moves) > 0
+ valid_moves = [move.id for move in valid_moves]
+ return len(valid_moves) > 0 and valid_moves or False
account_move()
@@ -1503,9 +1518,9 @@ class account_tax_code(osv.osv):
if context is None:
context = {}
move_state = ('posted', )
- if 'state' in context and context['state'] == 'all':
+ if context.get('state', False) == 'all':
move_state = ('draft', 'posted', )
- if 'fiscalyear_id' in context and context['fiscalyear_id']:
+ if context.get('fiscalyear_id', False):
fiscalyear_id = context['fiscalyear_id']
else:
fiscalyear_id = self.pool.get('account.fiscalyear').find(cr, uid, exception=False)
@@ -1523,9 +1538,9 @@ class account_tax_code(osv.osv):
if context is None:
context = {}
move_state = ('posted', )
- if 'state' in context and context['state'] == 'all':
+ if context.get('state', False) == 'all':
move_state = ('draft', 'posted', )
- if 'period_id' in context and context['period_id']:
+ if context.get('period_id', False):
period_id = context['period_id']
else:
period_id = self.pool.get('account.period').find(cr, uid)
@@ -1548,7 +1563,7 @@ class account_tax_code(osv.osv):
'child_ids': fields.one2many('account.tax.code', 'parent_id', 'Child Codes'),
'line_ids': fields.one2many('account.move.line', 'tax_code_id', 'Lines'),
'company_id': fields.many2one('res.company', 'Company', required=True),
- 'sign': fields.float('Sign for parent', required=True),
+ 'sign': fields.float('Coefficent for parent', required=True, help='You can specify here the coefficient that will be used when consolidating the amount of this case into its parent. For example, set 1/-1 if you want to add/substract it.'),
'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"),
}
@@ -1578,8 +1593,8 @@ class account_tax_code(osv.osv):
return self.pool.get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
_defaults = {
'company_id': _default_company,
- 'sign': lambda *args: 1.0,
- 'notprintable': lambda *a: False,
+ 'sign': 1.0,
+ 'notprintable': False,
}
def copy(self, cr, uid, id, default=None, context=None):
@@ -1969,7 +1984,6 @@ class account_model(osv.osv):
_description = "Account Model"
_columns = {
'name': fields.char('Model Name', size=64, required=True, help="This is a model for recurring accounting entries"),
- 'ref': fields.char('Reference', size=64),
'journal_id': fields.many2one('account.journal', 'Journal', required=True),
'company_id': fields.many2one('res.company', 'Company', required=True),
'lines_id': fields.one2many('account.model.line', 'model_id', 'Model Entries'),
@@ -1978,29 +1992,58 @@ class account_model(osv.osv):
_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'),
- 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id
+ 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id,
}
def generate(self, cr, uid, ids, datas={}, context={}):
move_ids = []
- for model in self.browse(cr, uid, ids, context):
+ entry = {}
+ account_move_obj = self.pool.get('account.move')
+ account_move_line_obj = self.pool.get('account.move.line')
+ pt_obj = self.pool.get('account.payment.term')
+
+ if datas.get('date', False):
context.update({'date':datas['date']})
- period_id = self.pool.get('account.period').find(cr, uid, dt=context.get('date', False))
- if not period_id:
- raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !'))
- period_id = period_id[0]
- move_id = self.pool.get('account.move').create(cr, uid, {
- 'ref': model.ref,
+ period_id = self.pool.get('account.period').find(cr, uid, dt=context.get('date', False))
+
+ if not period_id:
+ raise osv.except_osv(_('No period found !'), _('Unable to find a valid period !'))
+ period_id = period_id[0]
+
+ for model in self.browse(cr, uid, ids, context):
+ entry['name'] = model.name%{'year':time.strftime('%Y'), 'month':time.strftime('%m'), 'date':time.strftime('%d')}
+ move_id = account_move_obj.create(cr, uid, {
+ 'ref': entry['name'],
'period_id': period_id,
'journal_id': model.journal_id.id,
'date': context.get('date',time.strftime('%Y-%m-%d'))
})
move_ids.append(move_id)
for line in model.lines_id:
+ analytic_account_id = False
+ if line.analytic_account_id:
+ if not model.journal_id.analytic_journal_id:
+ raise osv.except_osv(_('No Analytic Journal !'),_("You have to define an analytic journal on the '%s' journal!") % (model.journal_id.name,))
+ analytic_account_id = line.analytic_account_id.id
val = {
'move_id': move_id,
'journal_id': model.journal_id.id,
- 'period_id': period_id
+ 'period_id': period_id,
+ 'analytic_account_id': analytic_account_id
}
+
+ 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)))
+ 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)
+ if pterm_list:
+ pterm_list = [l[0] for l in pterm_list]
+ pterm_list.sort()
+ date_maturity = pterm_list[-1]
+
val.update({
'name': line.name,
'quantity': line.quantity,
@@ -2008,14 +2051,13 @@ class account_model(osv.osv):
'credit': line.credit,
'account_id': line.account_id.id,
'move_id': move_id,
- 'ref': line.ref,
'partner_id': line.partner_id.id,
'date': context.get('date',time.strftime('%Y-%m-%d')),
- 'date_maturity': time.strftime('%Y-%m-%d')
+ 'date_maturity': date_maturity
})
c = context.copy()
c.update({'journal_id': model.journal_id.id,'period_id': period_id})
- self.pool.get('account.move.line').create(cr, uid, val, context=c)
+ account_move_line_obj.create(cr, uid, val, context=c)
return move_ids
account_model()
@@ -2028,22 +2070,13 @@ class account_model_line(osv.osv):
'quantity': fields.float('Quantity', digits_compute=dp.get_precision('Account'), help="The optional quantity on entries"),
'debit': fields.float('Debit', digits_compute=dp.get_precision('Account')),
'credit': fields.float('Credit', digits_compute=dp.get_precision('Account')),
-
'account_id': fields.many2one('account.account', 'Account', required=True, ondelete="cascade"),
-
+ 'analytic_account_id': fields.many2one('account.analytic.account', 'Analytic Account', ondelete="cascade"),
'model_id': fields.many2one('account.model', 'Model', required=True, ondelete="cascade", select=True),
-
- 'ref': fields.char('Reference', size=16),
-
'amount_currency': fields.float('Amount Currency', help="The amount expressed in an optional other currency."),
'currency_id': fields.many2one('res.currency', 'Currency'),
-
'partner_id': fields.many2one('res.partner', 'Partner'),
- 'date_maturity': fields.selection([('today','Date of the day'), ('partner','Partner Payment Term')], 'Due date', help="The due date of the generated entries for this model. You can choose between the creation date or the creation date of the entries plus the partner payment terms."),
- 'date': fields.selection([('today','Date of the day'), ('partner','Partner Payment Term')], 'Current Date', required=True, help="The date of the generated entries"),
- }
- _defaults = {
- 'date': lambda *a: 'today'
+ 'date_maturity': fields.selection([('today','Date of the day'), ('partner','Partner Payment Term')], 'Maturity date', help="The maturity date of the generated entries for this model. You can choose between the creation date or the creation date of the entries plus the partner payment terms."),
}
_order = 'sequence'
_sql_constraints = [
@@ -2074,11 +2107,11 @@ class account_subscription(osv.osv):
'lines_id': fields.one2many('account.subscription.line', 'subscription_id', 'Subscription Lines')
}
_defaults = {
- 'date_start': lambda *a: time.strftime('%Y-%m-%d'),
- 'period_type': lambda *a: 'month',
- 'period_total': lambda *a: 12,
- 'period_nbr': lambda *a: 1,
- 'state': lambda *a: 'draft',
+ 'date_start': time.strftime('%Y-%m-%d'),
+ 'period_type': 'month',
+ 'period_total': 12,
+ 'period_nbr': 1,
+ 'state': 'draft',
}
def state_draft(self, cr, uid, ids, context={}):
self.write(cr, uid, ids, {'state':'draft'})
@@ -2138,16 +2171,18 @@ class account_subscription_line(osv.osv):
def move_create(self, cr, uid, ids, context=None):
tocheck = {}
+ all_moves = []
for line in self.browse(cr, uid, ids, context=context):
datas = {
'date': line.date,
}
- ids = self.pool.get('account.model').generate(cr, uid, [line.subscription_id.model_id.id], datas, context)
+ move_ids = self.pool.get('account.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':ids[0]})
+ self.write(cr, uid, [line.id], {'move_id':move_ids[0]})
+ all_moves.extend(move_ids)
if tocheck:
self.pool.get('account.subscription').check(cr, uid, tocheck.keys(), context)
- return ids
+ return all_moves
_rec_name = 'date'
account_subscription_line()
@@ -2174,6 +2209,7 @@ class account_account_template(osv.osv):
('payable','Payable'),
('view','View'),
('consolidation','Consolidation'),
+ ('liquidity','Liquidity'),
('other','Others'),
('closed','Closed'),
], 'Internal Type', required=True,help="This type is used to differentiate types with "\
@@ -2193,9 +2229,9 @@ class account_account_template(osv.osv):
}
_defaults = {
- 'reconcile': lambda *a: False,
- 'type' : lambda *a :'view',
- 'nocreate': lambda *a: False,
+ 'reconcile': False,
+ 'type' : 'view',
+ 'nocreate': False,
}
_check_recursion = check_cycle
@@ -2288,8 +2324,8 @@ class account_tax_code_template(osv.osv):
}
_defaults = {
- 'sign': lambda *args: 1.0,
- 'notprintable': lambda *a: False,
+ 'sign': 1.0,
+ 'notprintable': False,
}
def name_get(self, cr, uid, ids, context=None):
@@ -2389,17 +2425,17 @@ class account_tax_template(osv.osv):
_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''',
- 'applicable_type': lambda *a: 'true',
- 'type': lambda *a: 'percent',
- 'amount': lambda *a: 0,
- 'sequence': lambda *a: 1,
- 'tax_group': lambda *a: 'vat',
- 'ref_tax_sign': lambda *a: 1,
- 'ref_base_sign': lambda *a: 1,
- 'tax_sign': lambda *a: 1,
- 'base_sign': lambda *a: 1,
- 'include_base_amount': lambda *a: False,
- 'type_tax_use': lambda *a: 'all',
+ 'applicable_type': 'true',
+ 'type': 'percent',
+ 'amount': 0,
+ 'sequence': 1,
+ 'tax_group': 'vat',
+ 'ref_tax_sign': 1,
+ 'ref_base_sign': 1,
+ 'tax_sign': 1,
+ 'base_sign': 1,
+ 'include_base_amount': False,
+ 'type_tax_use': 'all',
}
_order = 'sequence'
@@ -2480,7 +2516,7 @@ class wizard_multi_charts_accounts(osv.osv_memory):
_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,
- 'code_digits': lambda *a:6,
+ 'code_digits': 6,
'seq_journal': True
}
diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py
index 36fc350dfb8..5a8ee0d4e8c 100644
--- a/addons/account/account_analytic_line.py
+++ b/addons/account/account_analytic_line.py
@@ -38,12 +38,15 @@ class account_analytic_line(osv.osv):
'journal_id' : fields.many2one('account.analytic.journal', 'Analytic Journal', required=True, ondelete='cascade', select=True),
'code' : fields.char('Code', size=8),
'ref': fields.char('Ref.', size=64),
+ 'currency_id': fields.related('move_id', 'currency_id', type='many2one', relation='res.currency', string='Account currency', store=True, help="The related account currency if not equal to the company one.", readonly=True),
+ 'amount_currency': fields.related('move_id', 'amount_currency', type='float', string='Amount currency', store=True, help="The amount expressed in the related account currency if not equal to the company one.", readonly=True),
}
+
_defaults = {
'date': lambda *a: time.strftime('%Y-%m-%d'),
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=c),
}
- _order = 'date'
+ _order = 'date desc'
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
if context is None:
@@ -70,13 +73,16 @@ class account_analytic_line(osv.osv):
# Compute the cost based on the price type define into company
# property_valuation_price_type property
def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount,company_id,
- unit=False, context=None):
+ unit=False, journal_id=False, context=None):
if context==None:
context={}
uom_obj = self.pool.get('product.uom')
product_obj = self.pool.get('product.product')
company_obj=self.pool.get('res.company')
+ analytic_journal_obj=self.pool.get('account.analytic.journal')
+ product_price_type_obj = self.pool.get('product.price.type')
if prod_id:
+ result = 0.0
prod = product_obj.browse(cr, uid, prod_id)
a = prod.product_tmpl_id.property_account_expense.id
if not a:
@@ -88,16 +94,27 @@ class account_analytic_line(osv.osv):
(prod.name, prod.id,))
if not company_id:
company_id=company_obj._company_default_get(cr, uid, 'account.analytic.line', context)
-
+ flag = False
# Compute based on pricetype
- pricetype=self.pool.get('product.price.type').browse(cr, uid, company_obj.browse(cr,uid,company_id).property_valuation_price_type.id)
+ pricetype=product_price_type_obj.browse(cr, uid, company_obj.browse(cr,uid,company_id).property_valuation_price_type.id)
+ if journal_id:
+ journal = analytic_journal_obj.browse(cr, uid, journal_id)
+ if journal.type == 'sale':
+ product_price_type_ids = product_price_type_obj.search(cr, uid, [('field','=','list_price')], context)
+ if product_price_type_ids:
+ pricetype = product_price_type_obj.browse(cr, uid, product_price_type_ids, context)[0]
# Take the company currency as the reference one
+ if pricetype.field == 'list_price':
+ flag = True
amount_unit = prod.price_get(pricetype.field, context)[prod.id]
amount = amount_unit*unit_amount or 1.0
prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')
amount = amount_unit*unit_amount or 1.0
+ result = round(amount, prec)
+ if not flag:
+ result *= -1
return {'value': {
- 'amount': - round(amount, prec),
+ 'amount': result,
'general_account_id': a,
}}
return {}
@@ -114,52 +131,6 @@ class account_analytic_line(osv.osv):
account_analytic_line()
-
-class timesheet_invoice(osv.osv):
- _name = "report.hr.timesheet.invoice.journal"
- _description = "Analytic Account Costs and Revenues"
- _auto = False
- _columns = {
- 'name': fields.char('Year',size=64,required=False, readonly=True),
- 'account_id':fields.many2one('account.analytic.account', 'Analytic Account', readonly=True, select=True),
- 'journal_id': fields.many2one('account.analytic.journal', 'Journal', readonly=True),
- 'quantity': fields.float('Quantities', readonly=True),
- 'cost': fields.float('Credit', readonly=True),
- 'revenue': fields.float('Debit', readonly=True),
- 'month':fields.selection([('01','January'), ('02','February'), ('03','March'), ('04','April'), ('05','May'), ('06','June'),
- ('07','July'), ('08','August'), ('09','September'), ('10','October'), ('11','November'), ('12','December')],'Month',readonly=True),
- }
- _order = 'name desc, account_id'
- def init(self, cr):
- tools.drop_view_if_exists(cr, 'report_hr_timesheet_invoice_journal')
- cr.execute("""
- create or replace view report_hr_timesheet_invoice_journal as (
- select
- min(l.id) as id,
- to_char(l.date, 'YYYY') as name,
- to_char(l.date,'MM') as month,
- sum(
- CASE WHEN l.amount>0 THEN 0 ELSE l.amount
- END
- ) as cost,
- sum(
- CASE WHEN l.amount>0 THEN l.amount ELSE 0
- END
- ) as revenue,
- sum(l.unit_amount* COALESCE(u.factor, 1)) as quantity,
- journal_id,
- account_id
- from account_analytic_line l
- LEFT OUTER join product_uom u on (u.id=l.product_uom_id)
- group by
- to_char(l.date, 'YYYY'),
- to_char(l.date,'MM'),
- journal_id,
- account_id
- )""")
-timesheet_invoice()
-
-
class res_partner(osv.osv):
""" Inherits partner and adds contract information in the partner form """
_inherit = 'res.partner'
diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py
index f7c943f71d3..b6c9a889476 100644
--- a/addons/account/account_bank_statement.py
+++ b/addons/account/account_bank_statement.py
@@ -141,6 +141,7 @@ class account_bank_statement(osv.osv):
'balance_end_real': fields.float('Ending Balance', digits_compute=dp.get_precision('Account'),
states={'confirm':[('readonly', True)]}),
'balance_end': fields.function(_end_balance, method=True, string='Balance'),
+ 'company_id': fields.related('journal_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, required=True),
'line_ids': fields.one2many('account.bank.statement.line',
'statement_id', 'Statement lines',
states={'confirm':[('readonly', True)]}),
@@ -626,13 +627,15 @@ account_bank_statement_reconcile_line()
class account_bank_statement_line(osv.osv):
def onchange_partner_id(self, cursor, user, line_id, partner_id, type, currency_id, context=None):
+ res_users_obj = self.pool.get('res.users')
+ res_currency_obj = self.pool.get('res.currency')
res = {'value': {}}
obj_partner = self.pool.get('res.partner')
if context is None:
context = {}
if not partner_id:
return res
-
+ account_id = False
line = self.browse(cursor, user, line_id)
if not line or (line and not line[0].account_id):
part = obj_partner.browse(cursor, user, partner_id, context=context)
@@ -642,9 +645,7 @@ class account_bank_statement_line(osv.osv):
account_id = part.property_account_receivable.id
res['value']['account_id'] = account_id
- if not line or (line and not line[0].amount):
- res_users_obj = self.pool.get('res.users')
- res_currency_obj = self.pool.get('res.currency')
+ if account_id and (not line or (line and not line[0].amount)) and not context.get('amount', False):
company_currency_id = res_users_obj.browse(cursor, user, user,
context=context).company_id.currency_id.id
if not currency_id:
@@ -710,6 +711,7 @@ class account_bank_statement_line(osv.osv):
'reconcile_amount': fields.function(_reconcile_amount,
string='Amount reconciled', method=True, type='float'),
'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of bank statement lines."),
+ 'company_id': fields.related('statement_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, required=True),
}
_defaults = {
'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement.line'),
@@ -720,4 +722,4 @@ class account_bank_statement_line(osv.osv):
account_bank_statement_line()
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py
index 5ed057536a8..01d292ce23e 100644
--- a/addons/account/account_cash_statement.py
+++ b/addons/account/account_cash_statement.py
@@ -151,17 +151,37 @@ class account_cash_statement(osv.osv):
res[r] = round(res[r], 2)
return res
- def _get_company(self, cr, uid, ids, context={}):
+ def _get_company(self, cr, uid, context={}):
user_pool = self.pool.get('res.users')
company_pool = self.pool.get('res.company')
- user = user_pool.browse(cr, uid, uid, uid)
+ user = user_pool.browse(cr, uid, uid, context)
company_id = user.company_id and user.company_id.id
if not company_id:
company_id = company_pool.search(cr, uid, [])[0]
return company_id
- def _get_cash_open_box_lines(self, cr, uid, ids, context={}):
+ def _get_cash_open_box_lines(self, cr, uid, context={}):
+ res = []
+ curr = [1, 2, 5, 10, 20, 50, 100, 500]
+ for rs in curr:
+ dct = {
+ 'pieces':rs,
+ 'number':0
+ }
+ res.append(dct)
+ journal_ids = self.pool.get('account.journal').search(cr, uid, [('type','=','cash')], context=context)
+ if journal_ids:
+ results = self.search(cr, uid, [('journal_id','in',journal_ids),('state','=','confirm')],context=context)
+ if results:
+ cash_st = self.browse(cr, uid, results, context)[0]
+ for cash_line in cash_st.ending_details_ids:
+ for r in res:
+ if cash_line.pieces == r['pieces']:
+ r['number'] = cash_line.number
+ return res
+
+ def _get_default_cash_close_box_lines(self, cr, uid, context={}):
res = []
curr = [1, 2, 5, 10, 20, 50, 100, 500]
for rs in curr:
@@ -172,7 +192,7 @@ class account_cash_statement(osv.osv):
res.append(dct)
return res
- def _get_cash_close_box_lines(self, cr, uid, ids, context={}):
+ def _get_cash_close_box_lines(self, cr, ids, uid, context={}):
res = []
curr = [1, 2, 5, 10, 20, 50, 100, 500]
for rs in curr:
@@ -180,16 +200,16 @@ class account_cash_statement(osv.osv):
'pieces':rs,
'number':0
}
- res.append((0, 0, dct))
+ res.append((0,0,dct))
return res
_columns = {
- 'company_id':fields.many2one('res.company', 'Company', required=False),
- 'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'confirm': [('readonly', True)]}, domain=[('type', '=', 'cash')]),
+ 'company_id':fields.many2one('res.company', 'Company', required=True, states={'draft': [('readonly', False)]}, readonly=True,),
+ 'journal_id': fields.many2one('account.journal', 'Journal', required=True, states={'draft': [('readonly', False)]}, readonly=True, domain=[('type', '=', 'cash')]),
'balance_end_real': fields.float('Closing Balance', digits_compute=dp.get_precision('Account'), states={'confirm':[('readonly', True)]}, help="closing balance entered by the cashbox verifier"),
'state': fields.selection(
[('draft', 'Draft'),
- ('confirm', 'Confirmed'),
+ ('confirm', 'Closed'),
('open','Open')], 'State', required=True, states={'confirm': [('readonly', True)]}, readonly="1"),
'total_entry_encoding':fields.function(_get_sum_entry_encoding, method=True, store=True, string="Cash Transaction", help="Total cash transactions"),
'closing_date':fields.datetime("Closed On"),
@@ -197,7 +217,7 @@ class account_cash_statement(osv.osv):
'balance_end_cash': fields.function(_balance_end_cash, method=True, store=True, string='Balance', help="Closing balance based on cashBox"),
'starting_details_ids': fields.one2many('account.cashbox.line', 'starting_id', string='Opening Cashbox'),
'ending_details_ids': fields.one2many('account.cashbox.line', 'ending_id', string='Closing Cashbox'),
- 'name': fields.char('Name', size=64, required=True, readonly=False, help='if you give the Name other then / , its created Accounting Entries Move will be with same name as statement name. This allows the statement entries to have the same references than the statement itself'),
+ 'name': fields.char('Name', size=64, required=True, states={'draft': [('readonly', False)]}, readonly=True, help='if you give the Name other then / , its created Accounting Entries Move will be with same name as statement name. This allows the statement entries to have the same references than the statement itself'),
'user_id':fields.many2one('res.users', 'Responsible', required=False),
}
_defaults = {
@@ -206,7 +226,7 @@ class account_cash_statement(osv.osv):
'user_id': lambda self, cr, uid, context=None: uid,
'company_id': _get_company,
'starting_details_ids':_get_cash_open_box_lines,
- 'ending_details_ids':_get_cash_open_box_lines
+ 'ending_details_ids':_get_default_cash_close_box_lines
}
def create(self, cr, uid, vals, context=None):
@@ -305,25 +325,25 @@ class account_cash_statement(osv.osv):
'name': number
})
- cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm'))
- rs = cr.fetchone()
- rs = rs and rs[0] or None
- if rs:
- if len(statement.starting_details_ids) > 0:
- sid = []
- for line in statement.starting_details_ids:
- sid.append(line.id)
- cash_pool.unlink(cr, uid, sid)
-
- statement = statement_pool.browse(cr, uid, rs)
- balance_start = statement.balance_end_real or 0.0
- open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)])
- for sid in open_ids:
- default = {
- 'ending_id': False,
- 'starting_id':ids[0]
- }
- cash_pool.copy(cr, uid, sid, default)
+# cr.execute("select id from account_bank_statement where journal_id=%s and user_id=%s and state=%s order by id desc limit 1", (statement.journal_id.id, uid, 'confirm'))
+# rs = cr.fetchone()
+# rs = rs and rs[0] or None
+# if rs:
+# if len(statement.starting_details_ids) > 0:
+# sid = []
+# for line in statement.starting_details_ids:
+# sid.append(line.id)
+# cash_pool.unlink(cr, uid, sid)
+#
+# statement = statement_pool.browse(cr, uid, rs)
+# balance_start = statement.balance_end_real or 0.0
+# open_ids = cash_pool.search(cr, uid, [('ending_id','=',statement.id)])
+# for sid in open_ids:
+# default = {
+# 'ending_id': False,
+# 'starting_id':ids[0]
+# }
+# cash_pool.copy(cr, uid, sid, default)
vals.update({
'date':time.strftime("%Y-%m-%d %H:%M:%S"),
diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml
index 9b355c1fece..81391e796b9 100644
--- a/addons/account/account_invoice_view.xml
+++ b/addons/account/account_invoice_view.xml
@@ -211,11 +211,11 @@