Skip to content

Commit

Permalink
[MERGE] forward port branch saas-11.3 up to cd5c8a0
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Jan 29, 2019
2 parents 95ef460 + cd5c8a0 commit bdfef60
Show file tree
Hide file tree
Showing 25 changed files with 396 additions and 53 deletions.
12 changes: 11 additions & 1 deletion addons/account/models/account_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ def process_reconciliation(self, counterpart_aml_dicts=None, payment_aml_rec=Non
:returns: The journal entries with which the transaction was matched. If there was at least an entry in counterpart_aml_dicts or new_aml_dicts, this list contains
the move created by the reconciliation, containing entries for the statement.line (1), the counterpart move lines (0..*) and the new move lines (0..*).
"""
payable_account_type = self.env.ref('account.data_account_type_payable')
receivable_account_type = self.env.ref('account.data_account_type_receivable')
counterpart_aml_dicts = counterpart_aml_dicts or []
payment_aml_rec = payment_aml_rec or self.env['account.move.line']
new_aml_dicts = new_aml_dicts or []
Expand All @@ -540,10 +542,16 @@ def process_reconciliation(self, counterpart_aml_dicts=None, payment_aml_rec=Non
raise UserError(_('A selected move line was already reconciled.'))
if isinstance(aml_dict['move_line'], pycompat.integer_types):
aml_dict['move_line'] = aml_obj.browse(aml_dict['move_line'])

account_types = self.env['account.account.type']
for aml_dict in (counterpart_aml_dicts + new_aml_dicts):
if aml_dict.get('tax_ids') and isinstance(aml_dict['tax_ids'][0], pycompat.integer_types):
# Transform the value in the format required for One2many and Many2many fields
aml_dict['tax_ids'] = [(4, id, None) for id in aml_dict['tax_ids']]

user_type_id = self.env['account.account'].browse(aml_dict.get('account_id')).user_type_id
if user_type_id in [payable_account_type, receivable_account_type] and user_type_id not in account_types:
account_types |= user_type_id
if any(line.journal_entry_ids for line in self):
raise UserError(_('A selected statement line was already reconciled with an account move.'))

Expand Down Expand Up @@ -580,7 +588,9 @@ def process_reconciliation(self, counterpart_aml_dicts=None, payment_aml_rec=Non
if abs(total)>0.00001:
partner_id = self.partner_id and self.partner_id.id or False
partner_type = False
if partner_id:
if partner_id and len(account_types) == 1:
partner_type = 'customer' if account_types == receivable_account_type else 'supplier'
if partner_id and not partner_type:
if total < 0:
partner_type = 'supplier'
else:
Expand Down
26 changes: 25 additions & 1 deletion addons/account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,13 @@ def _get_outstanding_info_JSON(self):
amount_to_show = currency._convert(abs(line.amount_residual), self.currency_id, self.company_id, line.date or fields.Date.today())
if float_is_zero(amount_to_show, precision_rounding=self.currency_id.rounding):
continue
if line.ref :
title = '%s : %s' % (line.move_id.name, line.ref)
else:
title = line.move_id.name
info['content'].append({
'journal_name': line.ref or line.move_id.name,
'title': title,
'amount': amount_to_show,
'currency': currency_id.symbol,
'id': line.id,
Expand Down Expand Up @@ -1378,6 +1383,20 @@ def _refund_cleanup_lines(self, lines):
return result

@api.model
def _refund_tax_lines_account_change(self, lines, taxes_to_change):
# Let's change the account on tax lines when
# @param {list} lines: a list of orm commands
# @param {dict} taxes_to_change
# key: tax ID, value: refund account

if not taxes_to_change:
return lines

for line in lines:
if isinstance(line[2], dict) and line[2]['tax_id'] in taxes_to_change:
line[2]['account_id'] = taxes_to_change[line[2]['tax_id']]
return lines

def _get_refund_common_fields(self):
return ['partner_id', 'payment_term_id', 'account_id', 'currency_id', 'journal_id']

Expand Down Expand Up @@ -1423,7 +1442,12 @@ def _prepare_refund(self, invoice, date_invoice=None, date=None, description=Non
values['invoice_line_ids'] = self._refund_cleanup_lines(invoice.invoice_line_ids)

tax_lines = invoice.tax_line_ids
values['tax_line_ids'] = self._refund_cleanup_lines(tax_lines)
taxes_to_change = {
line.tax_id.id: line.tax_id.refund_account_id.id
for line in tax_lines.filtered(lambda l: l.tax_id.refund_account_id != l.tax_id.account_id)
}
cleaned_tax_lines = self._refund_cleanup_lines(tax_lines)
values['tax_line_ids'] = self._refund_tax_lines_account_change(cleaned_tax_lines, taxes_to_change)

if journal_id:
journal = self.env['account.journal'].browse(journal_id)
Expand Down
4 changes: 2 additions & 2 deletions addons/account/static/src/xml/account_payment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<td>
<a title="assign to invoice" role="button" class="oe_form_field btn btn-link outstanding_credit_assign" t-att-data-id="line.id" style="margin-right: 10px;" href="#">Add</a>
</td>
<td>
<span class="oe_form_field" style="margin-right: 30px;"><t t-esc="line.journal_name"></t></span>
<td style="max-width: 10em;">
<div class="oe_form_field" style="margin-right: 30px; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;" t-att-title="line.title"><t t-esc="line.journal_name"></t></div>
</td>
</t>
<t t-if="!outstanding">
Expand Down
56 changes: 56 additions & 0 deletions addons/account/tests/test_account_customer_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,62 @@ def test_customer_invoice_tax(self):

self.assertEquals(invoice.amount_untaxed, sum([x.base for x in invoice.tax_line_ids]))

def test_customer_invoice_tax_refund(self):
company = self.env.user.company_id
tax_account = self.env['account.account'].create({
'name': 'TAX',
'code': 'TAX',
'user_type_id': self.env.ref('account.data_account_type_current_assets').id,
'company_id': company.id,
})

tax_refund_account = self.env['account.account'].create({
'name': 'TAX_REFUND',
'code': 'TAX_R',
'user_type_id': self.env.ref('account.data_account_type_current_assets').id,
'company_id': company.id,
})

journalrec = self.env['account.journal'].search([('type', '=', 'sale')])[0]
partner3 = self.env.ref('base.res_partner_3')
account_id = self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id

tax = self.env['account.tax'].create({
'name': 'Tax 15.0',
'amount': 15.0,
'amount_type': 'percent',
'type_tax_use': 'sale',
'account_id': tax_account.id,
'refund_account_id': tax_refund_account.id
})

invoice_line_data = [
(0, 0,
{
'product_id': self.env.ref('product.product_product_1').id,
'quantity': 40.0,
'account_id': account_id,
'name': 'product test 1',
'discount': 10.00,
'price_unit': 2.27,
'invoice_line_tax_ids': [(6, 0, [tax.id])],
}
)]

invoice = self.env['account.invoice'].create(dict(
name="Test Customer Invoice",
reference_type="none",
journal_id=journalrec.id,
partner_id=partner3.id,
invoice_line_ids=invoice_line_data
))

invoice.action_invoice_open()

refund = invoice.refund()
self.assertEqual(invoice.tax_line_ids.mapped('account_id'), tax_account)
self.assertEqual(refund.tax_line_ids.mapped('account_id'), tax_refund_account)

def test_customer_invoice_dashboard(self):
def patched_today(*args, **kwargs):
return '2019-01-22'
Expand Down
2 changes: 1 addition & 1 deletion addons/l10n_fr/data/account_chart_template_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<record id="pcg_120" model="account.account.template">
<field name="name">Résultat de l'exercice (bénéfice)</field>
<field name="code">120</field>
<field name="user_type_id" ref="account.data_unaffected_earnings"/>
<field name="user_type_id" ref="account.data_account_type_current_liabilities"/>
<field name="chart_template_id" ref="l10n_fr_pcg_chart_template"/>
</record>

Expand Down
3 changes: 2 additions & 1 deletion addons/mail/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,8 @@ def message_route_process(self, message, message_dict, routes):
subtype = 'mail.mt_note'
if message_dict.get('parent_id'):
parent_message = self.env['mail.message'].sudo().browse(message_dict['parent_id'])
partner_ids = [(4, parent_message.author_id.id)]
if parent_message.author_id:
partner_ids = [(4, parent_message.author_id.id)]
else:
subtype = 'mail.mt_comment'

Expand Down
2 changes: 1 addition & 1 deletion addons/mail/static/src/js/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ var BasicActivity = AbstractField.extend({
var self = this;
var $markDoneBtn = $(ev.currentTarget);
var activityID = $markDoneBtn.data('activity-id');
var previousActivityTypeID = $markDoneBtn.data('previous-activity-type-id');
var previousActivityTypeID = $markDoneBtn.data('previous-activity-type-id') || false;
var forceNextActivity = $markDoneBtn.data('force-next-activity');

if ($markDoneBtn.data('toggle') == 'collapse') {
Expand Down
1 change: 1 addition & 0 deletions addons/mass_mailing/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from . import mass_mailing
from . import mass_mailing_stats
from . import mail_mail
from . import mail_template
from . import mail_thread
from . import res_config_settings
from . import mass_mailing_report
Expand Down
22 changes: 22 additions & 0 deletions addons/mass_mailing/models/mail_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, models


class MailTemplate(models.Model):
_inherit = "mail.template"

@api.model
def render_post_process(self, html):
# super will transform relative url to absolute
html = super(MailTemplate, self).render_post_process(html)

# apply shortener after
if self.env.context.get('post_convert_links'):
html = self.env['link.tracker'].convert_links(
html,
self.env.context['post_convert_links'],
blacklist=['/unsubscribe_from_list']
)
return html
21 changes: 17 additions & 4 deletions addons/mass_mailing/models/mass_mailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,21 @@ def _get_opt_out_list(self):
_logger.info("Mass-mailing %s targets %s, no opt out list available", self, target._name)
return opt_out

def _get_convert_links(self):
self.ensure_one()
utm_mixin = self.mass_mailing_campaign_id if self.mass_mailing_campaign_id else self
vals = {'mass_mailing_id': self.id}

if self.mass_mailing_campaign_id:
vals['mass_mailing_campaign_id'] = self.mass_mailing_campaign_id.id
if utm_mixin.campaign_id:
vals['campaign_id'] = utm_mixin.campaign_id.id
if utm_mixin.source_id:
vals['source_id'] = utm_mixin.source_id.id
if utm_mixin.medium_id:
vals['medium_id'] = utm_mixin.medium_id.id
return vals

def _get_seen_list(self):
"""Returns a set of emails already targeted by current mailing/campaign (no duplicates)"""
self.ensure_one()
Expand Down Expand Up @@ -814,6 +829,7 @@ def _get_mass_mailing_context(self):
return {
'mass_mailing_opt_out_list': self._get_opt_out_list(),
'mass_mailing_seen_list': self._get_seen_list(),
'post_convert_links': self._get_convert_links(),
}

def get_recipients(self):
Expand Down Expand Up @@ -855,13 +871,10 @@ def send_mail(self, res_ids=None):
if not res_ids:
raise UserError(_('There is no recipients selected.'))

# Convert links in absolute URLs before the application of the shortener
mailing.body_html = self.env['mail.thread']._replace_local_links(mailing.body_html)

composer_values = {
'author_id': author_id,
'attachment_ids': [(4, attachment.id) for attachment in mailing.attachment_ids],
'body': mailing.convert_links()[mailing.id],
'body': mailing.body_html,
'subject': mailing.name,
'model': mailing.mailing_model_real,
'email_from': mailing.email_from,
Expand Down
1 change: 1 addition & 0 deletions addons/mass_mailing/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from . import test_mass_mailing_list_merge
from . import test_mass_mailing_shortener
Loading

0 comments on commit bdfef60

Please sign in to comment.