diff --git a/addons/account/models/account.py b/addons/account/models/account.py
index 3a77abfc046..8482e7661ab 100644
--- a/addons/account/models/account.py
+++ b/addons/account/models/account.py
@@ -225,7 +225,7 @@ class AccountJournal(models.Model):
help="Company related to this journal")
analytic_journal_id = fields.Many2one('account.analytic.journal', string='Analytic Journal', help="Journal for analytic entries")
- refund_sequence = fields.Boolean(string='Dedicated Refund Sequence', help="Check this box if you don't want to share the same sequence for invoices and refunds made from this journal")
+ refund_sequence = fields.Boolean(string='Dedicated Refund Sequence', help="Check this box if you don't want to share the same sequence for invoices and refunds made from this journal", default=True)
inbound_payment_method_ids = fields.Many2many('account.payment.method', 'account_journal_inbound_payment_method_rel', 'journal_id', 'inbound_payment_method',
domain=[('payment_type', '=', 'inbound')], string='Debit Methods', default=lambda self: self._default_inbound_payment_methods(),
@@ -328,8 +328,6 @@ class AccountJournal(models.Model):
def _create_sequence(self, vals, refund=False):
""" Create new no_gap entry sequence for every new Journal"""
prefix = self._get_sequence_prefix(vals['code'], refund)
- if refund:
- prefix = 'R' + prefix
seq = {
'name': vals['name'],
'implementation': 'no_gap',
@@ -407,7 +405,7 @@ class AccountJournal(models.Model):
# We just need to create the relevant sequences according to the chosen options
if not vals.get('sequence_id'):
vals.update({'sequence_id': self.sudo()._create_sequence(vals).id})
- if vals.get('refund_sequence') and not vals.get('refund_sequence_id'):
+ if vals.get('type') in ('sale', 'puchase') and vals.get('refund_sequence') and not vals.get('refund_sequence_id'):
vals.update({'refund_sequence_id': self.sudo()._create_sequence(vals, refund=True).id})
journal = super(AccountJournal, self).create(vals)
diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index 2701039e974..5421242c29f 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -44,13 +44,14 @@ class AccountInvoice(models.Model):
self.amount_untaxed = sum(line.price_subtotal for line in self.invoice_line_ids)
self.amount_tax = sum(line.amount for line in self.tax_line_ids)
self.amount_total = self.amount_untaxed + self.amount_tax
- amount_total_signed = self.amount_total
+ amount_total_company_signed = self.amount_total
amount_untaxed_signed = self.amount_untaxed
if self.currency_id and self.currency_id != self.company_id.currency_id:
- amount_total_signed = self.currency_id.compute(self.amount_total, self.company_id.currency_id)
+ amount_total_company_signed = self.currency_id.compute(self.amount_total, self.company_id.currency_id)
amount_untaxed_signed = self.currency_id.compute(self.amount_untaxed, self.company_id.currency_id)
sign = self.type in ['in_refund', 'out_refund'] and -1 or 1
- self.amount_total_signed = amount_total_signed * sign
+ self.amount_total_company_signed = amount_total_company_signed * sign
+ self.amount_total_signed = self.amount_total * sign
self.amount_untaxed_signed = amount_untaxed_signed * sign
@api.model
@@ -91,16 +92,18 @@ class AccountInvoice(models.Model):
def _compute_residual(self):
residual = 0.0
residual_signed = 0.0
+ residual_company_signed = 0.0
sign = self.type in ['in_refund', 'in_invoice'] and -1 or 1
for line in self.sudo().move_id.line_ids:
if line.account_id.internal_type in ('receivable', 'payable'):
- residual_signed += line.amount_residual * sign
+ residual_company_signed += line.amount_residual * sign
if line.currency_id == self.currency_id:
residual += line.amount_residual_currency if line.currency_id else line.amount_residual
else:
from_currency = (line.currency_id and line.currency_id.with_context(date=line.date)) or line.company_id.currency_id.with_context(date=line.date)
residual += from_currency.compute(line.amount_residual, self.currency_id)
- self.residual_signed = residual_signed
+ self.residual_company_signed = residual_company_signed
+ self.residual_signed = abs(residual) * sign
self.residual = abs(residual)
digits_rounding_precision = self.currency_id.rounding
if float_is_zero(self.residual, digits_rounding_precision):
@@ -265,7 +268,10 @@ class AccountInvoice(models.Model):
store=True, readonly=True, compute='_compute_amount')
amount_total = fields.Monetary(string='Total',
store=True, readonly=True, compute='_compute_amount')
- amount_total_signed = fields.Monetary(string='Total', currency_field='company_currency_id',
+ amount_total_signed = fields.Monetary(string='Total', currency_field='currency_id',
+ store=True, readonly=True, compute='_compute_amount',
+ help="Total amount in the currency of the invoice, negative for credit notes.")
+ amount_total_company_signed = fields.Monetary(string='Total', currency_field='company_currency_id',
store=True, readonly=True, compute='_compute_amount',
help="Total amount in the currency of the company, negative for credit notes.")
currency_id = fields.Many2one('res.currency', string='Currency',
@@ -288,7 +294,9 @@ class AccountInvoice(models.Model):
residual = fields.Monetary(string='Amount Due',
compute='_compute_residual', store=True, help="Remaining amount due.")
- residual_signed = fields.Monetary(string='Amount Due', currency_field='company_currency_id',
+ residual_signed = fields.Monetary(string='Amount Due', currency_field='currency_id',
+ compute='_compute_residual', store=True, help="Remaining amount due in the currency of the invoice.")
+ residual_company_signed = fields.Monetary(string='Amount Due', currency_field='company_currency_id',
compute='_compute_residual', store=True, help="Remaining amount due in the currency of the company.")
payment_ids = fields.Many2many('account.payment', 'account_invoice_payment_rel', 'invoice_id', 'payment_id', string="Payments", copy=False, readonly=True)
payment_move_line_ids = fields.Many2many('account.move.line', string='Payments', compute='_compute_payments', store=True)
@@ -734,7 +742,7 @@ class AccountInvoice(models.Model):
}
ctx['company_id'] = inv.company_id.id
ctx['dont_create_taxes'] = True
- ctx['invoice_id'] = inv.move_name and inv or False
+ ctx['invoice'] = inv
ctx_nolang = ctx.copy()
ctx_nolang.pop('lang', None)
move = account_move.with_context(ctx_nolang).create(move_vals)
diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py
index 1fa41148208..d1e93f2fb29 100644
--- a/addons/account/models/account_journal_dashboard.py
+++ b/addons/account/models/account_journal_dashboard.py
@@ -111,7 +111,7 @@ class account_journal(models.Model):
data.append({'label':label,'value':0.0, 'type': 'past' if i<0 else 'future'})
# Build SQL query to find amount aggregated by week
- select_sql_clause = """SELECT sum(residual_signed) as total, min(date) as aggr_date from account_invoice where journal_id = %(journal_id)s and state = 'open'"""
+ select_sql_clause = """SELECT sum(residual_company_signed) as total, min(date) as aggr_date from account_invoice where journal_id = %(journal_id)s and state = 'open'"""
query = ''
start_date = (first_day_of_week + timedelta(days=-7))
for i in range(0,6):
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index 4d4d9afffde..61ec24fb777 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -118,7 +118,7 @@ class AccountMove(models.Model):
new_name = False
journal = move.journal_id
- if invoice and invoice.move_name:
+ if invoice and invoice.move_name != '/':
new_name = invoice.move_name
else:
if journal.sequence_id:
diff --git a/addons/account/models/account_payment.py b/addons/account/models/account_payment.py
index ee03ea35fa1..45fb04d520d 100644
--- a/addons/account/models/account_payment.py
+++ b/addons/account/models/account_payment.py
@@ -84,7 +84,7 @@ class account_abstract_payment(models.AbstractModel):
total = 0
payment_currency = self.currency_id or self.journal_id.currency_id or self.journal_id.company_id.currency_id
for inv in self._get_invoices():
- total += inv.residual_signed
+ total += inv.residual_company_signed
if self.company_id and self.company_id.currency_id != payment_currency:
total = self.company_id.currency_id.with_context(date=self.payment_date).compute(total, payment_currency)
return abs(total)
diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py
index de6361b288b..f81719fdfc8 100644
--- a/addons/account/models/partner.py
+++ b/addons/account/models/partner.py
@@ -250,31 +250,19 @@ class ResPartner(models.Model):
# generate where clause to include multicompany rules
where_query = account_invoice_report._where_calc([
- ('partner_id', 'in', all_partner_ids), ('state', 'not in', ['draft', 'cancel'])
+ ('partner_id', 'in', all_partner_ids), ('state', 'not in', ['draft', 'cancel']), ('company_id', '=', self.env.user.company_id.id)
])
account_invoice_report._apply_ir_rules(where_query, 'read')
from_clause, where_clause, where_clause_params = where_query.get_sql()
- query = """ WITH currency_rate (currency_id, rate, date_start, date_end) AS (
- SELECT r.currency_id, r.rate, r.name AS date_start,
- (SELECT name FROM res_currency_rate r2
- WHERE r2.name > r.name AND
- r2.currency_id = r.currency_id
- ORDER BY r2.name ASC
- LIMIT 1) AS date_end
- FROM res_currency_rate r
- )
- SELECT SUM(price_total * cr.rate) as total
- FROM account_invoice_report account_invoice_report, currency_rate cr
+ query = """
+ SELECT SUM(price_total) as total
+ FROM account_invoice_report account_invoice_report
WHERE %s
- AND cr.currency_id = %%s
- AND (COALESCE(account_invoice_report.date, NOW()) >= cr.date_start)
- AND (COALESCE(account_invoice_report.date, NOW()) < cr.date_end OR cr.date_end IS NULL)
""" % where_clause
- # price_total is in the currency with rate = 1
- # total_invoice should be displayed in the current user's currency
- self.env.cr.execute(query, where_clause_params + [user_currency_id])
+ # price_total is in the company currency
+ self.env.cr.execute(query, where_clause_params)
partner.total_invoiced = self.env.cr.fetchone()[0]
@api.multi
diff --git a/addons/account/report/account_invoice_report.py b/addons/account/report/account_invoice_report.py
index 4fdca689a89..8e5aaec22be 100644
--- a/addons/account/report/account_invoice_report.py
+++ b/addons/account/report/account_invoice_report.py
@@ -73,7 +73,7 @@ class AccountInvoiceReport(models.Model):
_depends = {
'account.invoice': [
- 'account_id', 'amount_total_signed', 'commercial_partner_id', 'company_id',
+ 'account_id', 'amount_total_company_signed', 'commercial_partner_id', 'company_id',
'currency_id', 'date_due', 'date_invoice', 'fiscal_position_id',
'journal_id', 'partner_bank_id', 'partner_id', 'payment_term_id',
'residual', 'state', 'type', 'user_id',
@@ -125,7 +125,7 @@ class AccountInvoiceReport(models.Model):
END
ELSE 1::numeric
END AS price_average,
- ai.residual_signed / (SELECT count(*) FROM account_invoice_line l where invoice_id = ai.id) *
+ ai.residual_company_signed / (SELECT count(*) FROM account_invoice_line l where invoice_id = ai.id) *
count(*) AS residual,
ai.commercial_partner_id as commercial_partner_id,
partner.country_id
@@ -149,8 +149,8 @@ class AccountInvoiceReport(models.Model):
GROUP BY ail.product_id, ail.account_analytic_id, ai.date_invoice, ai.id,
ai.partner_id, ai.payment_term_id, u2.name, u2.id, ai.currency_id, ai.journal_id,
ai.fiscal_position_id, ai.user_id, ai.company_id, ai.type, ai.state, pt.categ_id,
- ai.date_due, ai.account_id, ail.account_id, ai.partner_bank_id, ai.residual_signed,
- ai.amount_total_signed, ai.commercial_partner_id, partner.country_id
+ ai.date_due, ai.account_id, ail.account_id, ai.partner_bank_id, ai.residual_company_signed,
+ ai.amount_total_company_signed, ai.commercial_partner_id, partner.country_id
"""
return group_by_str
diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml
index 79e1f056d0b..5844364899f 100644
--- a/addons/account/views/account_invoice_view.xml
+++ b/addons/account/views/account_invoice_view.xml
@@ -9,7 +9,7 @@
-
+
@@ -20,7 +20,7 @@
-
+
@@ -31,7 +31,7 @@
-
+
@@ -133,8 +133,8 @@
-
-
+
+
@@ -194,8 +194,8 @@
-
-
+
+
@@ -295,7 +295,6 @@
-
@@ -440,7 +439,6 @@
-
@@ -543,7 +541,7 @@
Invoices
account.invoice
form
- tree,form,calendar,graph
+ tree,form,calendar,graph,pivot
[('type','in', ['out_invoice', 'out_refund']), ('state', 'not in', ['draft', 'cancel'])]
{'default_type':'out_invoice', 'type':'out_invoice', 'journal_type': 'sale'}