diff --git a/.mailmap b/.mailmap index 9e806a9ffa2..cb0c265368b 100644 --- a/.mailmap +++ b/.mailmap @@ -685,8 +685,7 @@ Paulius Sladkevičius Paulius Sladkevičius Paulius Sladkevičius Paulius Sladkevičius Paulius Sladkevičius Paulius Sladkevičius paulius <> -Pedro Manuel Baeza -Pedro Manuel Baeza +Pedro Manuel Baeza Peter Langenberg Peter Langenberg Peter Langenberg <> Philu philubert@gmail.com <> diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index d7c8372a79e..8f8afd6ddb0 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -262,7 +262,6 @@ class account_invoice(models.Model): store=True, readonly=True, compute='_compute_amount') amount_total = fields.Float(string='Total', digits=dp.get_precision('Account'), store=True, readonly=True, compute='_compute_amount') - currency_id = fields.Many2one('res.currency', string='Currency', required=True, readonly=True, states={'draft': [('readonly', False)]}, default=_default_currency, track_visibility='always') @@ -800,7 +799,7 @@ class account_invoice(models.Model): # create the analytical lines, one move line per invoice line iml = inv._get_analytic_lines() # check if taxes are all computed - compute_taxes = account_invoice_tax.compute(inv) + compute_taxes = account_invoice_tax.compute(inv.with_context(lang=inv.partner_id.lang)) inv.check_tax_lines(compute_taxes) # I disabled the check_total feature @@ -831,7 +830,7 @@ class account_invoice(models.Model): # create one move line for the total and possibly adjust the other lines amount total, total_currency, iml = inv.with_context(ctx).compute_invoice_totals(company_currency, ref, iml) - name = inv.name or inv.supplier_invoice_number or '/' + name = inv.supplier_invoice_number or inv.name or '/' totlines = [] if inv.payment_term: totlines = inv.with_context(ctx).payment_term.compute(total, date_invoice)[0] @@ -1131,7 +1130,7 @@ class account_invoice(models.Model): else: ref = self.number partner = self.partner_id._find_accounting_partner(self.partner_id) - name = name or self.invoice_line.name or self.number + name = name or self.invoice_line[0].name or self.number # Pay attention to the sign for both debit/credit AND amount_currency l1 = { 'name': name, @@ -1216,13 +1215,19 @@ class account_invoice_line(models.Model): @api.one @api.depends('price_unit', 'discount', 'invoice_line_tax_id', 'quantity', - 'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id') + 'product_id', 'invoice_id.partner_id', 'invoice_id.currency_id', 'invoice_id.company_id') def _compute_price(self): price = self.price_unit * (1 - (self.discount or 0.0) / 100.0) taxes = self.invoice_line_tax_id.compute_all(price, self.quantity, product=self.product_id, partner=self.invoice_id.partner_id) - self.price_subtotal = taxes['total'] + self.price_subtotal = price_subtotal_signed = taxes['total'] + if self.invoice_id.currency_id != self.invoice_id.company_id.currency_id: + price_subtotal_signed = self.invoice_id.currency_id.with_context(date=self.invoice_id.date_invoice).compute(price_subtotal_signed, self.company_id.currency_id) + sign = self.invoice_id.type in ['in_invoice', 'out_refund'] and -1 or 1 + self.price_subtotal_signed = price_subtotal_signed * sign + if self.invoice_id: self.price_subtotal = self.invoice_id.currency_id.round(self.price_subtotal) + self.price_subtotal_signed = self.invoice_id.currency_id.round(self.price_subtotal_signed) @api.model def _default_price_unit(self): @@ -1273,6 +1278,9 @@ class account_invoice_line(models.Model): default=_default_price_unit) price_subtotal = fields.Float(string='Amount', digits= dp.get_precision('Account'), store=True, readonly=True, compute='_compute_price') + price_subtotal_signed = fields.Float(string='Amount Signed', digits=0, + store=True, readonly=True, compute='_compute_price', + help="Total amount in the currency of the company, negative for credit notes.") quantity = fields.Float(string='Quantity', digits= dp.get_precision('Product Unit of Measure'), required=True, default=1) discount = fields.Float(string='Discount (%)', digits= dp.get_precision('Discount'), @@ -1304,7 +1312,7 @@ class account_invoice_line(models.Model): @api.multi def product_id_change(self, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, - company_id=None): + company_id=None, date_invoice=None): context = self._context company_id = company_id if company_id is not None else context.get('company_id', False) self = self.with_context(company_id=company_id, force_company=company_id) @@ -1362,7 +1370,7 @@ class account_invoice_line(models.Model): if company.currency_id != currency: if type in ('in_invoice', 'in_refund'): values['price_unit'] = product.standard_price - values['price_unit'] = values['price_unit'] * currency.rate + values['price_unit'] = values['price_unit'] * currency.with_context(dict(context or {}, date=date_invoice)).rate if values['uos_id'] and values['uos_id'] != product.uom_id.id: values['price_unit'] = self.env['product.uom']._compute_price( @@ -1372,14 +1380,14 @@ class account_invoice_line(models.Model): @api.multi def uos_id_change(self, product, uom, qty=0, name='', type='out_invoice', partner_id=False, - fposition_id=False, price_unit=False, currency_id=False, company_id=None): + fposition_id=False, price_unit=False, currency_id=False, company_id=None, date_invoice=None): context = self._context company_id = company_id if company_id != None else context.get('company_id', False) self = self.with_context(company_id=company_id) result = self.product_id_change( product, uom, qty, name, type, partner_id, fposition_id, price_unit, - currency_id, company_id=company_id, + currency_id, company_id=company_id, date_invoice=date_invoice ) warning = {} if not uom: @@ -1454,7 +1462,7 @@ class account_invoice_line(models.Model): # Set the tax field according to the account and the fiscal position # @api.multi - def onchange_account_id(self, product_id, partner_id, inv_type, fposition_id, account_id): + def onchange_account_id(self, product_id, partner_id, inv_type, fposition_id, account_id, date_invoice=None): if not account_id: return {} unique_tax_ids = [] @@ -1464,7 +1472,7 @@ class account_invoice_line(models.Model): unique_tax_ids = fpos.map_tax(account.tax_ids).ids else: product_change_result = self.product_id_change(product_id, False, type=inv_type, - partner_id=partner_id, fposition_id=fposition_id, company_id=account.company_id.id) + partner_id=partner_id, fposition_id=fposition_id, company_id=account.company_id.id, date_invoice=date_invoice) if 'invoice_line_tax_id' in product_change_result.get('value', {}): unique_tax_ids = product_change_result['value']['invoice_line_tax_id'] return {'value': {'invoice_line_tax_id': unique_tax_ids}} @@ -1521,12 +1529,11 @@ class account_invoice_tax(models.Model): @api.multi def amount_change(self, amount, currency_id=False, company_id=False, date_invoice=False): - factor = self.factor_tax if self else 1 company = self.env['res.company'].browse(company_id) if currency_id and company.currency_id: currency = self.env['res.currency'].browse(currency_id) currency = currency.with_context(date=date_invoice or fields.Date.context_today(self)) - amount = currency.compute(amount * factor, company.currency_id, round=False) + amount = currency.compute(amount, company.currency_id, round=False) return {'value': {'tax_amount': amount}} @api.v8 diff --git a/addons/account/account_invoice_view.xml b/addons/account/account_invoice_view.xml index 5fd16afa4ee..e983b489784 100644 --- a/addons/account/account_invoice_view.xml +++ b/addons/account/account_invoice_view.xml @@ -60,18 +60,18 @@ + on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)" context="{'partner_id': parent.partner_id}"/> - + @@ -209,17 +209,17 @@ + on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)" context="{'partner_id': parent.partner_id}"/> + on_change="onchange_account_id(product_id, parent.partner_id, parent.type, parent.fiscal_position,account_id, parent.date_invoice)"/> + on_change="uos_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)"/> - + @@ -367,17 +367,17 @@ + on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)"/> + on_change="onchange_account_id(product_id, parent.partner_id, parent.type, parent.fiscal_position,account_id, parent.date_invoice)"/> + on_change="uos_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, parent.company_id, parent.date_invoice, context)"/> + + + tree + + + + + + form + + + + Pending Invoice account.invoice diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index dcdbd9da785..9bed6f7120c 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -813,7 +813,7 @@ class account_move_line(osv.osv): # For already reconciled lines, don't use amount_residual(_currency) if line.account_id.type == 'liquidity': amount = abs(debit - credit) - amount_currency = line.amount_currency + amount_currency = abs(line.amount_currency) # Get right debit / credit: target_currency = target_currency or company_currency @@ -851,7 +851,12 @@ class account_move_line(osv.osv): ret.append(ret_line) return ret - def list_partners_to_reconcile(self, cr, uid, context=None): + + def list_partners_to_reconcile(self, cr, uid, context=None, filter_domain=False): + line_ids = [] + if filter_domain: + line_ids = self.search(cr, uid, filter_domain, context=context) + where_clause = filter_domain and "AND l.id = ANY(%s)" or "" cr.execute( """SELECT partner_id FROM ( SELECT l.partner_id, p.last_reconciliation_date, SUM(l.debit) AS debit, SUM(l.credit) AS credit, MAX(l.create_date) AS max_date @@ -861,10 +866,12 @@ class account_move_line(osv.osv): WHERE a.reconcile IS TRUE AND l.reconcile_id IS NULL AND l.state <> 'draft' + %s GROUP BY l.partner_id, p.last_reconciliation_date ) AS s WHERE debit > 0 AND credit > 0 AND (last_reconciliation_date IS NULL OR max_date > last_reconciliation_date) - ORDER BY last_reconciliation_date""") + ORDER BY last_reconciliation_date""" + % where_clause, (line_ids,)) ids = [x[0] for x in cr.fetchall()] if not ids: return [] diff --git a/addons/account/partner.py b/addons/account/partner.py index 4ca4abde46e..99357348295 100644 --- a/addons/account/partner.py +++ b/addons/account/partner.py @@ -251,13 +251,14 @@ class res_partner(osv.osv): def _journal_item_count(self, cr, uid, ids, field_name, arg, context=None): MoveLine = self.pool('account.move.line') AnalyticAccount = self.pool('account.analytic.account') - return { - partner_id: { - 'journal_item_count': MoveLine.search_count(cr, uid, [('partner_id', '=', partner_id)], context=context), - 'contracts_count': AnalyticAccount.search_count(cr,uid, [('partner_id', '=', partner_id)], context=context) - } - for partner_id in ids - } + results = {} + for partner_id in ids: + results[partner_id] = {} + if 'contracts_count' in field_name: + results[partner_id]['contracts_count'] = AnalyticAccount.search_count(cr, uid, [('partner_id', '=', partner_id)], context=context) + if 'journal_item_count' in field_name: + results[partner_id]['journal_item_count'] = MoveLine.search_count(cr, uid, [('partner_id', 'child_of', partner_id)], context=context) + return results def has_something_to_reconcile(self, cr, uid, partner_id, context=None): ''' diff --git a/addons/account/product_view.xml b/addons/account/product_view.xml index a008d1b6af7..f3ca33cbeb5 100644 --- a/addons/account/product_view.xml +++ b/addons/account/product_view.xml @@ -28,21 +28,6 @@ - - product.template.search - product.template - primary - - - - - - - - - - - product.category.property.form.inherit product.category diff --git a/addons/account/report/account_partner_ledger.py b/addons/account/report/account_partner_ledger.py index 1862d6336d8..8b1bc7e7b54 100644 --- a/addons/account/report/account_partner_ledger.py +++ b/addons/account/report/account_partner_ledger.py @@ -24,13 +24,14 @@ from openerp.osv import osv from openerp.tools.translate import _ from openerp.report import report_sxw from common_report_header import common_report_header - +from openerp import SUPERUSER_ID class third_party_ledger(report_sxw.rml_parse, common_report_header): def __init__(self, cr, uid, name, context=None): super(third_party_ledger, self).__init__(cr, uid, name, context=context) self.init_bal_sum = 0.0 + self.amount_currency = {} self.localcontext.update({ 'time': time, 'lines': self.lines, @@ -50,6 +51,7 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): 'display_initial_balance':self._display_initial_balance, 'display_currency':self._display_currency, 'get_target_move': self._get_target_move, + 'amount_currency': self.amount_currency, }) def _get_filter(self, data): @@ -70,7 +72,10 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): if data['form']['filter'] == 'unreconciled': self.reconcil = False self.result_selection = data['form'].get('result_selection', 'customer') - self.amount_currency = data['form'].get('amount_currency', False) + if data['form'].get('amount_currency'): + self.amount_currency['currency'] = True + else: + self.amount_currency.pop('currency', False) self.target_move = data['form'].get('target_move', 'all') PARTNER_REQUEST = '' move_state = ['draft','posted'] @@ -96,6 +101,7 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): if (data['model'] == 'res.partner') and ids: PARTNER_REQUEST = "AND l.partner_id IN %s" params += [tuple(ids)] + reconcile = "" if self.reconcil else "AND l.reconcile_id IS NULL " self.cr.execute( "SELECT DISTINCT l.partner_id " \ "FROM account_move_line AS l, account_account AS account, " \ @@ -104,12 +110,12 @@ class third_party_ledger(report_sxw.rml_parse, common_report_header): "AND l.account_id = account.id " \ "AND am.id = l.move_id " \ "AND am.state IN %s" -# "AND " + self.query +" " \ + "AND " + self.query +" " \ "AND l.account_id IN %s " \ " " + PARTNER_REQUEST + " " \ - "AND account.active ", params) + "AND account.active " + reconcile + " ", params) self.partner_ids = [res['partner_id'] for res in self.cr.dictfetchall()] - objects = obj_partner.browse(self.cr, self.uid, self.partner_ids) + objects = obj_partner.browse(self.cr, SUPERUSER_ID, self.partner_ids) objects = sorted(objects, key=lambda x: (x.ref, x.name)) return super(third_party_ledger, self).set_context(objects, data, self.partner_ids, report_type) diff --git a/addons/account/res_config_view.xml b/addons/account/res_config_view.xml index a2283c5f9c1..50012c870e4 100644 --- a/addons/account/res_config_view.xml +++ b/addons/account/res_config_view.xml @@ -93,7 +93,8 @@