diff --git a/addons/account/account.py b/addons/account/account.py index e92bd3a7879..e355658d047 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1059,10 +1059,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 +1858,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 +1884,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 +2799,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 29197a97b07..151c057ba39 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/report/account_print_invoice.rml b/addons/account/report/account_print_invoice.rml index 9268c94d4c7..3582221df44 100644 --- a/addons/account/report/account_print_invoice.rml +++ b/addons/account/report/account_print_invoice.rml @@ -99,42 +99,39 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -144,12 +141,12 @@ - Description - Taxes - Quantity - Unit Price - Disc.(%) - Price + Description + Taxes + Quantity + Unit Price + Disc.(%) + Price @@ -172,29 +169,29 @@ - Invoice [[ ((o.type == 'out_invoice' and (o.state == 'open' or o.state == 'paid')) or removeParentNode('para')) and '' ]] [[ o.number ]] - PRO-FORMA [[ ((o.type == 'out_invoice' and o.state == 'proforma2') or removeParentNode('para')) and '' ]] - Draft Invoice [[ ((o.type == 'out_invoice' and o.state == 'draft') or removeParentNode('para')) and '' ]] - Cancelled Invoice [[ ((o.type == 'out_invoice' and o.state == 'cancel') or removeParentNode('para')) and '' ]] [[ o.number ]] - Refund [[ (o.type=='out_refund' or removeParentNode('para')) and '' ]] [[ o.number ]] - Supplier Refund [[ (o.type=='in_refund' or removeParentNode('para')) and '' ]] [[ o.number ]] - Supplier Invoice [[ (o.type=='in_invoice' or removeParentNode('para')) and '' ]] [[ o.number ]] + Invoice [[ ((o.type == 'out_invoice' and (o.state == 'open' or o.state == 'paid')) or removeParentNode('para')) and '' ]] [[ o.number ]] + PRO-FORMA [[ ((o.type == 'out_invoice' and o.state == 'proforma2') or removeParentNode('para')) and '' ]] + Draft Invoice [[ ((o.type == 'out_invoice' and o.state == 'draft') or removeParentNode('para')) and '' ]] + Cancelled Invoice [[ ((o.type == 'out_invoice' and o.state == 'cancel') or removeParentNode('para')) and '' ]] [[ o.number ]] + Refund [[ (o.type=='out_refund' or removeParentNode('para')) and '' ]] [[ o.number ]] + Supplier Refund [[ (o.type=='in_refund' or removeParentNode('para')) and '' ]] [[ o.number ]] + Supplier Invoice [[ (o.type=='in_invoice' or removeParentNode('para')) and '' ]] [[ o.number ]] - Description + Description - Invoice Date - - - Source + Invoice Date - Customer Code + Source + + + Customer Code @@ -220,22 +217,22 @@ - Description + Description - Taxes + Taxes - Quantity + Quantity - Unit Price + Unit Price - Disc.(%) + Disc.(%) - Price + Price @@ -298,10 +295,10 @@ - Total: + Total: - [[ formatLang(o.amount_total, digits=get_digits(dp='Account'), currency_obj=o.currency_id) ]] + [[ formatLang(o.amount_total, digits=get_digits(dp='Account'), currency_obj=o.currency_id) ]] @@ -311,13 +308,13 @@ - Tax [[ o.tax_line==[] and removeParentNode('blockTable') ]] + Tax [[ o.tax_line==[] and removeParentNode('blockTable') ]] - Base + Base - Amount + Amount @@ -361,7 +358,7 @@ - Fiscal Position Remark : + Fiscal Position Remark : [[ (o.fiscal_position and o.fiscal_position.note and format(o.fiscal_position.note)) or removeParentNode('blockTable') ]] diff --git a/addons/account_followup/account_followup_customers.xml b/addons/account_followup/account_followup_customers.xml index 6893abe012e..296e6624f79 100644 --- a/addons/account_followup/account_followup_customers.xml +++ b/addons/account_followup/account_followup_customers.xml @@ -97,7 +97,7 @@