Skip to content

Commit

Permalink
[MERGE] forward port branch saas-12 up to 6f8e40c
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Oct 27, 2016
2 parents ba33ec7 + 6f8e40c commit 3bb022d
Show file tree
Hide file tree
Showing 46 changed files with 673 additions and 211 deletions.
12 changes: 9 additions & 3 deletions addons/account/models/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,23 @@ def compute_all(self, price_unit, currency=None, quantity=1.0, product=None, par

if not round_tax:
prec += 5
total_excluded = total_included = base = round(price_unit * quantity, prec)

base_values = self.env.context.get('base_values')
if not base_values:
total_excluded = total_included = base = round(price_unit * quantity, prec)
else:
total_excluded, total_included, base = base_values

# Sorting key is mandatory in this case. When no key is provided, sorted() will perform a
# search. However, the search method is overridden in account.tax in order to add a domain
# depending on the context. This domain might filter out some taxes from self, e.g. in the
# case of group taxes.
for tax in self.sorted(key=lambda r: r.sequence):
if tax.amount_type == 'group':
ret = tax.children_tax_ids.compute_all(price_unit, currency, quantity, product, partner)
children = tax.children_tax_ids.with_context(base_values=(total_excluded, total_included, base))
ret = children.compute_all(price_unit, currency, quantity, product, partner)
total_excluded = ret['total_excluded']
base = ret['base']
base = ret['base'] if tax.include_base_amount else base
total_included = ret['total_included']
tax_amount = total_included - total_excluded
taxes += ret['taxes']
Expand Down
2 changes: 1 addition & 1 deletion addons/account/models/account_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ def reconciliation_widget_auto_reconcile(self, num_already_reconciled_lines):
'details': {
'name': _("Automatically reconciled items"),
'model': 'account.move',
'ids': automatic_reconciliation_entries.ids
'ids': automatic_reconciliation_entries.mapped('journal_entry_ids').ids
}
}]
return {
Expand Down
36 changes: 19 additions & 17 deletions addons/account/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,14 @@ def _prepare_tax_line_vals(self, line, tax):
'account_analytic_id': tax['analytic'] and line.account_analytic_id.id or False,
'account_id': self.type in ('out_invoice', 'in_invoice') and (tax['account_id'] or line.account_id.id) or (tax['refund_account_id'] or line.account_id.id),
}

# If the taxes generate moves on the same financial account as the invoice line,
# propagate the analytic account from the invoice line to the tax line.
# This is necessary in situations were (part of) the taxes cannot be reclaimed,
# to ensure the tax move is allocated to the proper analytic account.
if not vals.get('account_analytic_id') and line.account_analytic_id and vals['account_id'] == line.account_id.id:
vals['account_analytic_id'] = line.account_analytic_id.id

return vals

@api.multi
Expand All @@ -622,14 +630,6 @@ def get_taxes_values(self):
taxes = line.invoice_line_tax_ids.compute_all(price_unit, self.currency_id, line.quantity, line.product_id, self.partner_id)['taxes']
for tax in taxes:
val = self._prepare_tax_line_vals(line, tax)

# If the taxes generate moves on the same financial account as the invoice line,
# propagate the analytic account from the invoice line to the tax line.
# This is necessary in situations were (part of) the taxes cannot be reclaimed,
# to ensure the tax move is allocated to the proper analytic account.
if not val.get('account_analytic_id') and line.account_analytic_id and val['account_id'] == line.account_id.id:
val['account_analytic_id'] = line.account_analytic_id.id

key = self.env['account.tax'].browse(tax['id']).get_grouping_key(val)

if key not in tax_grouped:
Expand Down Expand Up @@ -1350,15 +1350,17 @@ def _compute_base_amount(self):
for invoice in self.mapped('invoice_id'):
tax_grouped[invoice.id] = invoice.get_taxes_values()
for tax in self:
key = self.env['account.tax'].browse(tax.tax_id.id).get_grouping_key({
'tax_id': tax.tax_id.id,
'account_id': tax.account_id.id,
'account_analytic_id': tax.account_analytic_id.id,
})
if tax.invoice_id and key in tax_grouped[tax.invoice_id.id]:
tax.base = tax_grouped[tax.invoice_id.id][key]['base']
else:
_logger.warning('Tax Base Amount not computable probably due to a change in an underlying tax (%s).', tax.tax_id.name)
tax.base = 0.0
if tax.tax_id:
key = tax.tax_id.get_grouping_key({
'tax_id': tax.tax_id.id,
'account_id': tax.account_id.id,
'account_analytic_id': tax.account_analytic_id.id,
})
if tax.invoice_id and key in tax_grouped[tax.invoice_id.id]:
tax.base = tax_grouped[tax.invoice_id.id][key]['base']
else:
_logger.warning('Tax Base Amount not computable probably due to a change in an underlying tax (%s).', tax.tax_id.name)

invoice_id = fields.Many2one('account.invoice', string='Invoice', ondelete='cascade', index=True)
name = fields.Char(string='Tax Description', required=True)
Expand Down
3 changes: 3 additions & 0 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,9 @@ def remove_move_reconcile(self):
return True
rec_move_ids = self.env['account.partial.reconcile']
for account_move_line in self:
for invoice in account_move_line.payment_id.invoice_ids:
if account_move_line in invoice.payment_move_line_ids:
account_move_line.payment_id.write({'invoice_ids': [(3, invoice.id, None)]})
rec_move_ids += account_move_line.matched_debit_ids
rec_move_ids += account_move_line.matched_credit_ids
return rec_move_ids.unlink()
Expand Down
2 changes: 1 addition & 1 deletion addons/account/report/account_invoice_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _compute_amounts_in_user_currency(self):
user_currency_price_total = fields.Float(string="Total Without Tax", compute='_compute_amounts_in_user_currency', digits=0)
price_average = fields.Float(string='Average Price', readonly=True, group_operator="avg")
user_currency_price_average = fields.Float(string="Average Price", compute='_compute_amounts_in_user_currency', digits=0)
currency_rate = fields.Float(string='Currency Rate', readonly=True)
currency_rate = fields.Float(string='Currency Rate', readonly=True, group_operator="avg")
nbr = fields.Integer(string='# of Lines', readonly=True) # TDE FIXME master: rename into nbr_lines
type = fields.Selection([
('out_invoice', 'Customer Invoice'),
Expand Down
36 changes: 36 additions & 0 deletions addons/account/tests/test_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,46 @@ def setUp(self):
(4, self.percent_tax.id, 0)
]
})
self.group_tax_bis = self.tax_model.create({
'name': "Group tax bis",
'amount_type': 'group',
'amount': 0,
'sequence': 6,
'children_tax_ids': [
(4, self.fixed_tax.id, 0),
(4, self.percent_tax.id, 0)
]
})
self.group_of_group_tax = self.tax_model.create({
'name': "Group of group tax",
'amount_type': 'group',
'amount': 0,
'sequence': 7,
'children_tax_ids': [
(4, self.group_tax.id, 0),
(4, self.group_tax_bis.id, 0)
]
})
self.bank_journal = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', '=', self.account_manager.company_id.id)])[0]
self.bank_account = self.bank_journal.default_debit_account_id
self.expense_account = self.env['account.account'].search([('user_type_id.type', '=', 'payable')], limit=1) #Should be done by onchange later

def test_tax_group_of_group_tax(self):
self.fixed_tax.include_base_amount = True
self.group_tax.include_base_amount = True
self.group_of_group_tax.include_base_amount = True
res = self.group_of_group_tax.compute_all(200.0)
self.assertEquals(res['total_excluded'], 200.0)
# After calculation of first group
# base = 210
# total_included = 231
# Base of the first grouped is passed
# Base after the second group (220) is dropped.
# Base of the group of groups is passed out,
# so we obtain base as after first group
self.assertEquals(res['base'], 210.0)
self.assertEquals(res['total_included'], 263.0)

def test_tax_group(self):
res = self.group_tax.compute_all(200.0)
self.assertEquals(res['total_excluded'], 200.0)
Expand Down
8 changes: 4 additions & 4 deletions addons/account/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@
<field name="user_id"/>
<field name="date_due"/>
<field name="origin"/>
<field name="amount_total_signed" string="Total"/>
<field name="residual_signed" string="Amount Due"/>
<field name="amount_total_signed" string="Total" sum="Total"/>
<field name="residual_signed" string="Amount Due" sum="Amount Due"/>
<field name="currency_id" invisible="1"/>
<field name="company_currency_id" invisible="1"/>
<field name="state"/>
Expand Down Expand Up @@ -200,8 +200,8 @@
<field name="company_id" groups="base.group_multi_company" options="{'no_create': True}"/>
<field name="date_due"/>
<field name="origin"/>
<field name="amount_total_signed" string="Total"/>
<field name="residual_signed" string="To Pay"/>
<field name="amount_total_signed" string="Total" sum="Total"/>
<field name="residual_signed" string="To Pay" sum="To pay"/>
<field name="currency_id" invisible="1"/>
<field name="company_currency_id" invisible="1"/>
<field name="state"/>
Expand Down
6 changes: 3 additions & 3 deletions addons/account/views/account_payment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<field name="journal_id"/>
<field name="payment_method_id"/>
<field name="partner_id" string="Customer"/>
<field name="amount"/>
<field name="amount" sum="Amount"/>
<field name="state"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="currency_id" invisible="1"/>
Expand All @@ -31,7 +31,7 @@
<field name="journal_id"/>
<field name="payment_method_id"/>
<field name="partner_id" string="Vendor"/>
<field name="amount"/>
<field name="amount" sum="Amount"/>
<field name="company_id" groups="base.group_multi_company"/>
<field name="state"/>
<field name="currency_id" invisible="1"/>
Expand Down Expand Up @@ -149,7 +149,7 @@
</p>
</field>
</record>

<record id="action_account_payments_payable" model="ir.actions.act_window">
<field name="name">Payments</field>
<field name="res_model">account.payment</field>
Expand Down
2 changes: 1 addition & 1 deletion addons/account/views/web_planner_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
<span class="fa fa-tasks fa-4x"></span>
<h3><strong>Revenue Recognition</strong></h3>
<p>Use in conjunction with contracts to calculate your monthly revenue for multi-month contracts.</p>
<a t-att-href="prepare_backend_url('base.open_module_tree', 'form', 'account_asset')"
<a t-att-href="prepare_backend_url('base.open_module_tree', 'form', 'account_deferred_revenue')"
class="btn odoo_purple">
<span class="fa fa-arrow-circle-o-down"/> Install Now
</a>
Expand Down
14 changes: 12 additions & 2 deletions addons/board/static/src/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ var DashBoard = form_common.FormWidget.extend({
},
on_close_action: function(e) {
if (confirm(_t("Are you sure you want to remove this item ?"))) {
$(e.currentTarget).parents('.oe_action:first').remove();
var $container = $(e.currentTarget).parents('.oe_action:first');
var am = _.findWhere(this.action_managers, { am_id: $container.data('am_id') });
am.destroy();
this.action_managers.splice(_.indexOf(this.action_managers, am), 1);
$container.remove();
this.do_save_dashboard();
}
},
Expand Down Expand Up @@ -223,7 +227,13 @@ var DashBoard = form_common.FormWidget.extend({
var am = new ActionManager(this),
// FIXME: ideally the dashboard view shall be refactored like kanban.
$action = $('#' + this.view.element_id + '_action_' + index);
$action.parent().data('action_attrs', action_attrs);
var $action_container = $action.closest('.oe_action');
var am_id = _.uniqueId('action_manager_');
am.am_id = am_id;
$action_container.data({
action_attrs: action_attrs,
am_id: am_id,
});
this.action_managers.push(am);
am.appendTo($action).then(function () {
am.do_action(action).then(function () {
Expand Down
Loading

0 comments on commit 3bb022d

Please sign in to comment.