Skip to content

Commit

Permalink
Commit funcional
Browse files Browse the repository at this point in the history
  • Loading branch information
morrillo committed May 17, 2020
1 parent 2742a73 commit a642f48
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 10 deletions.
1 change: 1 addition & 0 deletions l10n_ar_sale_additional_taxes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
from . import account_tax
64 changes: 64 additions & 0 deletions l10n_ar_sale_additional_taxes/account_tax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, _, fields, api, tools
from odoo.exceptions import UserError,ValidationError
from odoo.tools.safe_eval import safe_eval
import datetime
import math

class AccountTax(models.Model):
_inherit = 'account.tax'

def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None):
""" Returns the amount of a single tax. base_amount is the actual amount on which the tax is applied, which is
price_unit * quantity eventually affected by previous taxes (if tax is include_base_amount XOR price_include)
"""
self.ensure_one()

if self.amount_type == 'fixed':
# Use copysign to take into account the sign of the base amount which includes the sign
# of the quantity and the sign of the price_unit
# Amount is the fixed price for the tax, it can be negative
# Base amount included the sign of the quantity and the sign of the unit price and when
# a product is returned, it can be done either by changing the sign of quantity or by changing the
# sign of the price unit.
# When the price unit is equal to 0, the sign of the quantity is absorbed in base_amount then
# a "else" case is needed.
if base_amount:
return math.copysign(quantity, base_amount) * self.amount
else:
return quantity * self.amount

price_include = self._context.get('force_price_include', self.price_include)

# base * (1 + tax_amount) = new_base
if self.amount_type == 'percent' and not price_include:
#if self.id == 8:
# raise ValidatoinError('estamos aca')
## import pdb;pdb.set_trace()
if self.is_padron:
amount = self.amount
if partner and partner.perception_ids:
for perception in partner.perception_ids:
if perception.tax_id.id == self.id:
amount = perception.percent
return base_amount * amount / 100
else:
return base_amount * self.amount / 100
# <=> new_base = base / (1 + tax_amount)
if self.amount_type == 'percent' and price_include:
return base_amount - (base_amount / (1 + self.amount / 100))
# base / (1 - tax_amount) = new_base
if self.amount_type == 'division' and not price_include:
return base_amount / (1 - self.amount / 100) - base_amount if (1 - self.amount / 100) else 0.0
# <=> new_base * (1 - tax_amount) = base
if self.amount_type == 'division' and price_include:
return base_amount - (base_amount * (self.amount / 100))


is_padron = fields.Boolean('Es padron?')
padron_prefix = fields.Char('Prefijo padron',default='')
pefijo_padron = fields.Char('Prefijo padron')
4 changes: 2 additions & 2 deletions l10n_ar_sale_additional_taxes/account_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<record id="additional_tax_tax_form" model="ir.ui.view">
<field name="name">additional.tax.account.tax.form.inherit</field>
<field name="model">account.tax</field>
<field name="type">form</field>
<field name="inherit_id" ref="account.view_tax_form"/>
<field name="arch" type="xml">
<field name="company_id" position="after">
<field name="prefijo_padron" />
<field name="padron_prefix" />
<field name="is_padron" />
</field>
</field>
</record>
Expand Down
47 changes: 39 additions & 8 deletions l10n_ar_sale_additional_taxes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ class AccountCheck(models.Model):
payment_date = fields.Date(readonly=True,states={'draft': [('readonly', False)],'holding': [('readonly', False)]},index=True,)


class AccountTax(models.Model):
_inherit = 'account.tax'

prefijo_padron = fields.Char('Prefijo padron')


class AccountPadron(models.Model):
_name = 'account.padron'
_description = 'account.padron'
Expand Down Expand Up @@ -76,10 +70,48 @@ def update_percepciones(self):

perception_ids = fields.One2many('res.partner.perception', 'partner_id', 'Percepciones Definidas')


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



def compute_taxes(self):
self.ensure_one()
if self.state == 'draft':
if self.type in ['out_invoice','out_refund']:
for move_tax in self.move_tax_ids:
move_tax.unlink()
if self.partner_id.perception_ids:
for perception in self.partner_id.perception_ids:
for invoice_line in self.invoice_line_ids:
if perception.tax_id.id not in invoice_line.tax_ids.ids:
invoice_line.tax_ids = [(4,perception.tax_id.id)]
for invoice_line in self.invoice_line_ids:
if invoice_line.tax_ids:
for tax in invoice_line.tax_ids.ids:
account_tax = self.env['account.tax'].browse(tax)
move_tax_id = self.env['account.move.tax'].search([('move_id','=',self.id),('tax_id','=',tax)])
if not move_tax_id:
vals = {
'move_id': self.id,
'tax_id': tax
}
move_tax_id = self.env['account.move.tax'].create(vals)
move_tax_id.base_amount = move_tax_id.base_amount + invoice_line.price_subtotal
tax_id = self.env['account.tax'].browse(tax)
if not tax_id.is_padron:
move_tax_id.tax_amount = move_tax_id.tax_amount + invoice_line.price_subtotal * (account_tax.amount / 100)
else:
amount = 0
for perception in self.partner_id.perception_ids:
if perception.tax_id.id == tax_id.id:
amount = perception.percent
move_tax_id.tax_amount = move_tax_id.tax_amount + invoice_line.price_subtotal * (amount / 100)




"""
@api.depends(
'line_ids.debit',
'line_ids.credit',
Expand Down Expand Up @@ -137,7 +169,6 @@ def compute_taxes(self):
'move_id': self.id}
move_tax_id = self.env['account.move.tax'].create(vals)
"""
@api.multi
def compute_taxes(self):
Expand Down

0 comments on commit a642f48

Please sign in to comment.