Skip to content
Open

[?] #214

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions account_invoice_tax/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import wizards
from . import models
3 changes: 3 additions & 0 deletions account_invoice_tax/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import account_move
from . import account_move_line
from . import account_tax
24 changes: 24 additions & 0 deletions account_invoice_tax/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from odoo import models, fields, api


class AccountMove(models.Model):

_inherit = "account.move"

def _compute_tax_totals(self):
for move in self:
tax_context = {'inverse_invoice_currency_rate': move.inverse_invoice_currency_rate}
for line in move.line_ids.filtered(lambda x: x.tax_fixed_amount_in_currency):
#tax_context[line.tax_line_id.id] = line.tax_fixed_amount_in_currency
tax_context[line.tax_line_id.id] = {
'fixed_amount':line.tax_fixed_amount_in_currency,
'rate': line.tax_fixed_amount / line.tax_fixed_amount_in_currency
}
super(AccountMove, move.with_context(tax_context=tax_context))._compute_tax_totals()

# def button_draft(self):
# for move in self:
# tax_context = {'inverse_invoice_currency_rate': move.inverse_invoice_currency_rate}
# for line in move.line_ids.filtered(lambda x: x.tax_fixed_amount_in_currency):
# tax_context[line.tax_line_id.id] = line.tax_fixed_amount_in_currency
# super(AccountMove, move.with_context(tax_context=tax_context)).button_draft()
8 changes: 8 additions & 0 deletions account_invoice_tax/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import models, fields


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

tax_fixed_amount = fields.Float()
tax_fixed_amount_in_currency = fields.Float()
27 changes: 27 additions & 0 deletions account_invoice_tax/models/account_tax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import models, fields, api

class AccountTax(models.Model):

_inherit = "account.tax"

@api.model
def _get_tax_totals_summary(self, base_lines, currency, company, cash_rounding=None):
res = super()._get_tax_totals_summary(base_lines, currency, company, cash_rounding=cash_rounding)
if 'tax_context' in self.env.context:
rate = self.env.context.get('inverse_invoice_currency_rate', 1)
for tax_groups in res['subtotals'][0]['tax_groups']:
for involved_tax_id in tax_groups['involved_tax_ids']:
amount = self.env.context['tax_context'].get(involved_tax_id, {}).get('fixed_amount', 0.0)
rate = self.env.context['tax_context'].get(involved_tax_id, {}).get('rate', 1.0)
original_amount = tax_groups.get('tax_amount', {})
if amount and amount != original_amount:
tax_groups.update({
'tax_amount': amount,
'tax_amount_currency': amount
})
res['tax_amount'] += amount - original_amount
res['total_amount'] += amount - original_amount
res['tax_amount_currency'] += (amount - original_amount) * rate
res['total_amount_currency'] += (amount - original_amount) * rate

return res
20 changes: 16 additions & 4 deletions account_invoice_tax/wizards/account_invoice_tax.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ def default_get(self, fields):
res["move_id"] = move_ids[0].id if move_ids else False
lines = []
for line in move_ids[0].line_ids.filtered(lambda x: x.tax_line_id):
is_in_company_currency = move_ids[0].currency_id == move_ids[0].company_currency_id
vals = {
"tax_id": line.tax_line_id.id,
"amount": line.amount_currency,
"new_tax": False,
'amount_company_currency': line.amount_currency if is_in_company_currency else line.debit or line.credit,
}
lines.append(
Command.create({"tax_id": line.tax_line_id.id, "amount": line.amount_currency, "new_tax": False})
Command.create(vals)
)
res["tax_line_ids"] = lines

Expand Down Expand Up @@ -72,10 +79,15 @@ def action_update_tax(self):
and x.tax_repartition_line_id.tax_id.amount_type == "fixed"
):
tax_line.write(fixed_taxes_bu.get(tax_line.tax_line_id))

for tax_line_id in self.tax_line_ids:
# seteamos valor al impuesto segun lo que puso en el wizard
line_with_tax = move.line_ids.filtered(lambda x: x.tax_line_id == tax_line_id.tax_id)
line_with_tax.write(tax_line_id._get_amount_updated_values())
if line_with_tax.tax_repartition_line_id.tax_id.amount_type == "fixed":

line_with_tax.tax_fixed_amount = tax_line_id.amount_company_currency if self.is_in_company_currency else tax_line_id.amount
line_with_tax.tax_fixed_amount_in_currency = tax_line_id.amount

def add_tax_and_new(self):
self.add_tax()
Expand All @@ -101,9 +113,9 @@ class AccountInvoiceTaxLine(models.TransientModel):
tax_id = fields.Many2one("account.tax", required=True)
amount = fields.Float()
amount_company_currency = fields.Float(
compute="_compute_amount_company_currency",
readonly=False,
store=True,
# compute="_compute_amount_company_currency",
# readonly=False,
# store=True,
)

new_tax = fields.Boolean(default=True)
Expand Down
Loading