diff --git a/addons/account/account.py b/addons/account/account.py index 6a5b9b1cbae..eb5b227979b 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -20,11 +20,12 @@ ############################################################################## import time -from datetime import datetime, timedelta +from datetime import datetime from dateutil.relativedelta import relativedelta from operator import itemgetter import netsvc +import pooler from osv import fields, osv import decimal_precision as dp from tools.translate import _ @@ -613,6 +614,21 @@ class account_journal(osv.osv): 'user_id': lambda self,cr,uid,context: uid, 'company_id': lambda self,cr,uid,c: self.pool.get('res.users').browse(cr, uid, uid, c).company_id.id, } + _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): if 'company_id' in vals: @@ -1108,7 +1124,7 @@ class account_move(osv.osv): '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, } @@ -1583,7 +1599,6 @@ class account_tax_code(osv.osv): '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 = [] @@ -1626,7 +1641,7 @@ class account_tax_code(osv.osv): _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): @@ -1641,12 +1656,19 @@ 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_compute=dp.get_precision('Account'), help="For taxes of type percentage, 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','Percentage'), ('fixed','Fixed Amount'), ('none','None'), ('code','Python Code'), ('balance','Balance')], 'Tax Type', required=True, help="The computation method for the tax amount."), @@ -2135,7 +2157,7 @@ class account_subscription(osv.osv): '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, @@ -2700,9 +2722,17 @@ class wizard_multi_charts_accounts(osv.osv_memory): 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 @@ -2741,6 +2771,60 @@ class wizard_multi_charts_accounts(osv.osv_memory): 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 = obj_data.search(cr, uid, [('model','=','account.journal.view'), ('name','=','account_journal_bank_view')]) data = obj_data.browse(cr, uid, data_id[0]) @@ -2875,18 +2959,18 @@ class wizard_multi_charts_accounts(osv.osv_memory): 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: +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/account/account_analytic_line.py b/addons/account/account_analytic_line.py index 633cb09d976..329eb59ab05 100644 --- a/addons/account/account_analytic_line.py +++ b/addons/account/account_analytic_line.py @@ -64,8 +64,6 @@ class account_analytic_line(osv.osv): if l.move_id and not l.account_id.company_id.id == l.move_id.account_id.company_id.id: return False return True - _constraints = [ - ] # Compute the cost based on the price type define into company # property_valuation_price_type property @@ -75,17 +73,14 @@ class account_analytic_line(osv.osv): context={} if not journal_id: j_ids = self.pool.get('account.analytic.journal').search(cr, uid, [('type','=','purchase')]) - j_id = j_ids and j_ids[0] or False + journal_id = j_ids and j_ids[0] or False if not journal_id or not prod_id: return {} product_obj = self.pool.get('product.product') analytic_journal_obj =self.pool.get('account.analytic.journal') - company_obj = self.pool.get('res.company') product_price_type_obj = self.pool.get('product.price.type') j_id = analytic_journal_obj.browse(cr, uid, journal_id, context=context) prod = product_obj.browse(cr, uid, prod_id) - if not company_id: - company_id = j_id.company_id.id result = 0.0 if j_id.type <> 'sale': @@ -97,7 +92,6 @@ class account_analytic_line(osv.osv): _('There is no expense account defined ' \ 'for this product: "%s" (id:%d)') % \ (prod.name, prod.id,)) - amount_unit = prod.price_get('standard_price', context)[prod.id] else: a = prod.product_tmpl_id.property_account_income.id if not a: @@ -107,29 +101,32 @@ class account_analytic_line(osv.osv): _('There is no income account defined ' \ 'for this product: "%s" (id:%d)') % \ (prod.name, prod_id,)) - amount_unit = prod.price_get('list_price', context)[prod_id] - if not company_id: - company_id = company_obj._company_default_get(cr, uid, 'account.analytic.line', context=context) - flag = False - # Compute based on pricetype - product_price_type_ids = product_price_type_obj.search(cr, uid, [('field','=','standard_price')], context) - pricetype = product_price_type_obj.browse(cr, uid, product_price_type_ids, context)[0] - 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] - prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account') - amount = amount_unit*unit or 1.0 - result = round(amount, prec) - if not flag: - result *= -1 + flag = False + # Compute based on pricetype + product_price_type_ids = product_price_type_obj.search(cr, uid, [('field','=','standard_price')], context=context) + pricetype = product_price_type_obj.browse(cr, uid, product_price_type_ids, context)[0] + 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 + ctx = context.copy() + if unit: + # price_get() will respect a 'uom' in its context, in order + # to return a default price for those units + ctx['uom'] = unit + amount_unit = prod.price_get(pricetype.field, context=ctx)[prod.id] + prec = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account') + amount = amount_unit * quantity or 1.0 + result = round(amount, prec) + if not flag: + result *= -1 + return {'value': { 'amount': result, 'general_account_id': a, @@ -153,11 +150,10 @@ class res_partner(osv.osv): _inherit = 'res.partner' _columns = { - 'contract_ids': fields.one2many('account.analytic.account', \ + 'contract_ids': fields.one2many('account.analytic.account', \ 'partner_id', 'Contracts', readonly=True), - } + } res_partner() # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/addons/account/account_bank_statement.py b/addons/account/account_bank_statement.py index 8ee449e2fc9..0b03f52a1e9 100644 --- a/addons/account/account_bank_statement.py +++ b/addons/account/account_bank_statement.py @@ -43,30 +43,9 @@ class account_bank_statement(osv.osv): seq = 0 for line in statement.line_ids: seq += 1 - if not line.sequence: - account_bank_statement_line_obj.write(cr, uid, [line.id], {'sequence': seq}, context=context) + account_bank_statement_line_obj.write(cr, uid, [line.id], {'sequence': seq}, context=context) return res - def button_import_invoice(self, cr, uid, ids, context=None): - mod_obj = self.pool.get('ir.model.data') - if context is None: - context = {} - model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','view_account_statement_from_invoice')], context=context) - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] - context.update({'statement_id': ids[0]}) - - return { - 'name': _('Import Invoice'), - 'context': context, - 'view_type': 'form', - 'view_mode': 'tree,form', - 'res_model': 'account.statement.from.invoice', - 'views': [(resource_id,'form')], - 'type': 'ir.actions.act_window', - 'target': 'new', - 'nodestroy': True - } - def _default_journal_id(self, cr, uid, context={}): journal_pool = self.pool.get('account.journal') journal_type = context.get('journal_type', False) @@ -142,7 +121,7 @@ class account_bank_statement(osv.osv): res[statement_id] = (currency_id, currency_names[currency_id]) return res - _order = "date desc" + _order = "date desc, id desc" _name = "account.bank.statement" _description = "Bank Statement" _columns = { @@ -174,7 +153,7 @@ class account_bank_statement(osv.osv): _defaults = { 'name': "/", - 'date': time.strftime('%Y-%m-%d'), + 'date': lambda *a: time.strftime('%Y-%m-%d'), 'state': 'draft', 'balance_start': _default_balance_start, 'journal_id': _default_journal_id, @@ -316,7 +295,7 @@ class account_bank_statement(osv.osv): return move_id def get_next_st_line_number(self, cr, uid, st_number, st_line, context=None): - return st_number + ' - ' + str(st_line.sequence) + return st_number + '/' + str(st_line.sequence) def balance_check(self, cr, uid, st_id, journal_type='bank', context=None): st = self.browse(cr, uid, st_id, context) @@ -423,9 +402,7 @@ account_bank_statement() 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') + def onchange_type(self, cr, uid, line_id, partner_id, type, context=None): res = {'value': {}} obj_partner = self.pool.get('res.partner') if context is None: @@ -433,39 +410,21 @@ class account_bank_statement_line(osv.osv): if not partner_id: return res account_id = False - line = self.browse(cursor, user, line_id) + line = self.browse(cr, uid, line_id) if not line or (line and not line[0].account_id): - part = obj_partner.browse(cursor, user, partner_id, context=context) + part = obj_partner.browse(cr, uid, partner_id, context=context) if type == 'supplier': account_id = part.property_account_payable.id else: account_id = part.property_account_receivable.id res['value']['account_id'] = account_id - - 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: - currency_id = company_currency_id - - cursor.execute('SELECT sum(debit-credit) \ - FROM account_move_line \ - WHERE (reconcile_id is null) \ - AND partner_id = %s \ - AND account_id=%s', (partner_id, account_id)) - pgres = cursor.fetchone() - balance = pgres and pgres[0] or 0.0 - - balance = res_currency_obj.compute(cursor, user, company_currency_id, - currency_id, balance, context=context) - res['value']['amount'] = balance return res _order = "statement_id desc, sequence" _name = "account.bank.statement.line" _description = "Bank Statement Line" _columns = { - 'name': fields.char('Name', size=64, required=True), + 'name': fields.char('Communication', size=64, required=True), 'date': fields.date('Date', required=True), 'amount': fields.float('Amount'), 'type': fields.selection([ @@ -489,7 +448,7 @@ class account_bank_statement_line(osv.osv): } _defaults = { 'name': lambda self,cr,uid,context={}: self.pool.get('ir.sequence').get(cr, uid, 'account.bank.statement.line'), - 'date': time.strftime('%Y-%m-%d'), + 'date': lambda *a: time.strftime('%Y-%m-%d'), 'type': 'general', } diff --git a/addons/account/account_cash_statement.py b/addons/account/account_cash_statement.py index da6b93fdc22..ffcc979169d 100644 --- a/addons/account/account_cash_statement.py +++ b/addons/account/account_cash_statement.py @@ -233,15 +233,13 @@ class account_cash_statement(osv.osv): } _defaults = { 'state': 'draft', - 'date': time.strftime("%Y-%m-%d %H:%M:%S"), + 'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"), 'user_id': lambda self, cr, uid, context=None: uid, 'starting_details_ids': _get_cash_open_box_lines, 'ending_details_ids': _get_default_cash_close_box_lines } def create(self, cr, uid, vals, context=None): - if 'journal_id' not in vals: - raise osv.except_osv('Error', _('You cannot create a bank or cash register without a journal!')) sql = [ ('journal_id', '=', vals.get('journal_id', False)), ('state', '=', 'open') @@ -329,7 +327,7 @@ class account_cash_statement(osv.osv): for statement in statement_pool.browse(cr, uid, ids, context=context): vals = {} if not self._user_allow(cr, uid, statement.id, context=context): - raise osv.except_osv(_('Error !'), _('User %s does not have rights to access %s journal !' % (statement.user_id.name, statement.journal_id.name))) + raise osv.except_osv(_('Error !'), (_('User %s does not have rights to access %s journal !') % (statement.user_id.name, statement.journal_id.name))) if statement.name and statement.name == '/': number = self.pool.get('ir.sequence').get(cr, uid, 'account.cash.statement') diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index ffea12170a2..94c4acf24aa 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -488,7 +488,7 @@ class account_move_line(osv.osv): 'blocked': False, 'centralisation': 'normal', 'date': _get_date, - 'date_created': time.strftime('%Y-%m-%d'), + 'date_created': lambda *a: time.strftime('%Y-%m-%d'), 'state': 'draft', 'currency_id': _get_currency, 'journal_id': lambda self, cr, uid, c: c.get('journal_id', False), @@ -528,10 +528,18 @@ class account_move_line(osv.osv): return False return True + def _check_partner_id(self, cr, uid, ids): + lines = self.browse(cr, uid, ids) + for l in lines: + if l.account_id.type in ('receivable', 'payable') and not l.partner_id: + return False + return True + _constraints = [ (_check_no_view, 'You can not create move line on view account.', ['account_id']), (_check_no_closed, 'You can not create move line on closed account.', ['account_id']), - (_check_company_id,'Company must be same for its related account and period.',['company_id'] ), + (_check_company_id, 'Company must be same for its related account and period.',['company_id'] ), + (_check_partner_id, 'You can not create move line on receivable/payable account without partner', ['account_id'] ) ] #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id @@ -929,6 +937,9 @@ class account_move_line(osv.osv): elif field == 'date': attrs.append('on_change="onchange_date(date)"') + elif field == 'analytic_account_id': + attrs.append('''groups="analytic.group_analytic_accounting"''') # Currently it is not working due to framework problem may be .. + if field in ('amount_currency', 'currency_id'): attrs.append('on_change="onchange_currency(account_id, amount_currency, currency_id, date, journal_id)"') attrs.append('''attrs="{'readonly': [('state', '=', 'valid')]}"''') @@ -1101,6 +1112,10 @@ class account_move_line(osv.osv): journal_obj = self.pool.get('account.journal') if context is None: context = {} + if vals.get('move_id', False): + company_id = self.pool.get('account.move').read(cr, uid, vals['move_id'], ['company_id']).get('company_id', False) + if company_id: + vals['company_id'] = company_id[0] self._check_date(cr, uid, vals, context, check) if ('account_id' in vals) and not account_obj.read(cr, uid, vals['account_id'], ['active'])['active']: raise osv.except_osv(_('Bad account!'), _('You can not use an inactive account!')) diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 320d5b1089e..aaabc86d865 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -237,11 +237,11 @@ - account.treasory.graph + account.treasury.graph account.account graph - + @@ -555,12 +555,12 @@ - - - + + - - + + + @@ -568,8 +568,8 @@
- - + + @@ -983,7 +983,7 @@ - + @@ -1060,13 +1060,13 @@ - + - - + + @@ -1105,15 +1105,15 @@ - + - - + + @@ -1353,13 +1353,13 @@ - + - - + + @@ -1372,7 +1372,7 @@ - + @@ -1512,8 +1512,8 @@ - - + + @@ -1521,8 +1521,8 @@
- - + + @@ -1991,7 +1991,7 @@ - + @@ -2593,23 +2593,23 @@ action = self.pool.get('res.config').next(cr, uid, [], context) - - - + + - - + + + - + - - + + - + @@ -2673,7 +2673,7 @@ action = self.pool.get('res.config').next(cr, uid, [], context)