diff --git a/addons/account/account.py b/addons/account/account.py index e92bd3a7879..d65c5d62c0a 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1034,9 +1034,15 @@ class account_period(osv.osv): context = {} ids = [] if name: - ids = self.search(cr, user, [('code','ilike',name)]+ args, limit=limit) + ids = self.search(cr, user, + [('code', 'ilike', name)] + args, + limit=limit, + context=context) if not ids: - ids = self.search(cr, user, [('name',operator,name)]+ args, limit=limit) + ids = self.search(cr, user, + [('name', operator, name)] + args, + limit=limit, + context=context) return self.name_get(cr, user, ids, context=context) def write(self, cr, uid, ids, vals, context=None): @@ -1059,10 +1065,14 @@ class account_period(osv.osv): raise osv.except_osv(_('Error!'), _('You should choose the periods that belong to the same company.')) if period_date_start > period_date_stop: raise osv.except_osv(_('Error!'), _('Start period should precede then end period.')) + + # /!\ We do not include a criterion on the company_id field below, to allow producing consolidated reports + # on multiple companies. It will only work when start/end periods are selected and no fiscal year is chosen. + #for period from = january, we want to exclude the opening period (but it has same date_from, so we have to check if period_from is special or not to include that clause or not in the search). if period_from.special: - return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id)]) - return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id), ('special', '=', False)]) + return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop)]) + return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('special', '=', False)]) class account_journal_period(osv.osv): @@ -1854,6 +1864,12 @@ class account_tax_code(osv.osv): _order = 'code' +def get_precision_tax(): + def change_digit_tax(cr): + res = openerp.registry(cr.dbname)['decimal.precision'].precision_get(cr, SUPERUSER_ID, 'Account') + return (16, res+3) + return change_digit_tax + class account_tax(osv.osv): """ A tax object. @@ -1874,12 +1890,6 @@ class account_tax(osv.osv): default.update({'name': name + _(' (Copy)')}) return super(account_tax, self).copy_data(cr, uid, id, default=default, context=context) - def get_precision_tax(): - def change_digit_tax(cr): - res = openerp.registry(cr.dbname)['decimal.precision'].precision_get(cr, SUPERUSER_ID, 'Account') - return (16, res+2) - return change_digit_tax - _name = 'account.tax' _description = 'Tax' _columns = { @@ -2795,7 +2805,7 @@ class account_tax_template(osv.osv): 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True), 'name': fields.char('Tax Name', size=64, required=True), 'sequence': fields.integer('Sequence', required=True, help="The sequence field is used to order the taxes lines from lower sequences to higher ones. The order is important if you have a tax that has 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 Tax Type percent enter % ratio between 0-1."), 'type': fields.selection( [('percent','Percent'), ('fixed','Fixed'), ('none','None'), ('code','Python Code'), ('balance','Balance')], 'Tax Type', required=True), 'applicable_type': fields.selection( [('true','True'), ('code','Python Code')], 'Applicable Type', 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."), diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index ab6ad97b180..0c49bed2fb5 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -89,13 +89,43 @@ class account_invoice(osv.osv): return [('none', _('Free Reference'))] def _amount_residual(self, cr, uid, ids, name, args, context=None): + """Function of the field residua. It computes the residual amount (balance) for each invoice""" + if context is None: + context = {} + ctx = context.copy() result = {} + currency_obj = self.pool.get('res.currency') for invoice in self.browse(cr, uid, ids, context=context): + nb_inv_in_partial_rec = max_invoice_id = 0 result[invoice.id] = 0.0 if invoice.move_id: - for m in invoice.move_id.line_id: - if m.account_id.type in ('receivable','payable'): - result[invoice.id] += m.amount_residual_currency + for aml in invoice.move_id.line_id: + if aml.account_id.type in ('receivable','payable'): + if aml.currency_id and aml.currency_id.id == invoice.currency_id.id: + result[invoice.id] += aml.amount_residual_currency + else: + ctx['date'] = aml.date + result[invoice.id] += currency_obj.compute(cr, uid, aml.company_id.currency_id.id, invoice.currency_id.id, aml.amount_residual, context=ctx) + + if aml.reconcile_partial_id.line_partial_ids: + #we check if the invoice is partially reconciled and if there are other invoices + #involved in this partial reconciliation (and we sum these invoices) + for line in aml.reconcile_partial_id.line_partial_ids: + if line.invoice: + nb_inv_in_partial_rec += 1 + #store the max invoice id as for this invoice we will make a balance instead of a simple division + max_invoice_id = max(max_invoice_id, line.invoice.id) + if nb_inv_in_partial_rec: + #if there are several invoices in a partial reconciliation, we split the residual by the number + #of invoice to have a sum of residual amounts that matches the partner balance + new_value = currency_obj.round(cr, uid, invoice.currency_id, result[invoice.id] / nb_inv_in_partial_rec) + if invoice.id == max_invoice_id: + #if it's the last the invoice of the bunch of invoices partially reconciled together, we make a + #balance to avoid rounding errors + result[invoice.id] = result[invoice.id] - ((nb_inv_in_partial_rec - 1) * new_value) + else: + result[invoice.id] = new_value + #prevent the residual amount on the invoice to be less than 0 result[invoice.id] = max(result[invoice.id], 0.0) return result diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 7469c38decb..c71b97d5796 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -197,7 +197,7 @@ @@ -320,7 +320,7 @@ @@ -353,7 +353,7 @@ diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 603c4254b19..e921e639642 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -907,9 +907,7 @@