mirror of
https://bitbucket.org/presik/trytonpsk-account_col.git
synced 2023-12-14 05:53:00 +01:00
add option for remove tax when amount tax does not exceed
This commit is contained in:
parent
0236b65cf9
commit
2342c22838
7 changed files with 85 additions and 57 deletions
64
account.py
64
account.py
|
@ -1437,6 +1437,7 @@ class PartyWithholding(Report):
|
|||
|
||||
class AccountConfiguration(ModelSQL, ModelView):
|
||||
__name__ = 'account.configuration'
|
||||
|
||||
equivalent_invoice_sec = fields.Many2One('ir.sequence',
|
||||
'Equivalent Invoice', domain=[
|
||||
('code', '=', 'account.invoice')
|
||||
|
@ -1444,6 +1445,7 @@ class AccountConfiguration(ModelSQL, ModelView):
|
|||
template_email_confirm = fields.Many2One(
|
||||
'email.template', 'Template Email of Notification'
|
||||
)
|
||||
remove_tax = fields.Boolean('Remove Tax', help="Remove taxes on invoice if not exceeding the base")
|
||||
|
||||
|
||||
class AuxiliaryPartyStart(ModelView):
|
||||
|
@ -1518,6 +1520,10 @@ class PrintAuxiliaryParty(Wizard):
|
|||
accounts_ids = [acc.id for acc in self.start.accounts]
|
||||
else:
|
||||
accounts_ids = []
|
||||
|
||||
grouped_by_oc = False
|
||||
if hasattr(self.start, 'grouped_by_oc') and self.start.grouped_by_oc:
|
||||
grouped_by_oc = self.start.grouped_by_oc
|
||||
data = {
|
||||
'company': self.start.company.id,
|
||||
'start_period': start_period,
|
||||
|
@ -1530,6 +1536,7 @@ class PrintAuxiliaryParty(Wizard):
|
|||
'grouped_by_account': self.start.grouped_by_account,
|
||||
'grouped_by_location': self.start.grouped_by_location,
|
||||
'only_reference': self.start.only_reference,
|
||||
'grouped_by_oc': grouped_by_oc,
|
||||
}
|
||||
return action, data
|
||||
|
||||
|
@ -1591,6 +1598,7 @@ class AuxiliaryParty(Report):
|
|||
lines = MoveLine.search(dom_lines, order=[('move.date', 'ASC')])
|
||||
res = {}
|
||||
accounts_id = {}
|
||||
grouped_by_loc = False
|
||||
|
||||
if lines:
|
||||
for line in lines:
|
||||
|
@ -1606,48 +1614,52 @@ class AuxiliaryParty(Report):
|
|||
name = line.party.rec_name
|
||||
id_number = line.party.id_number
|
||||
account_id = line.account.id
|
||||
if data['grouped_by_location'] or data['grouped_by_oc']:
|
||||
grouped_by_loc = True
|
||||
if data['grouped_by_location']:
|
||||
city_name = ' '
|
||||
if line.party.city_name:
|
||||
city_name = line.party.city_name
|
||||
id_loc = city_name
|
||||
elif data['grouped_by_oc']:
|
||||
id_loc = 'CO.'
|
||||
if line.operation_center:
|
||||
id_loc = 'CO. [' + line.operation_center.code + '] ' + line.operation_center.name
|
||||
|
||||
if data['grouped_by_location']:
|
||||
|
||||
city_name = ' '
|
||||
if line.party.city_name:
|
||||
city_name = line.party.city_name
|
||||
id_city = city_name
|
||||
|
||||
if id_city not in res.keys():
|
||||
res[id_city] = {}
|
||||
accounts_id[id_city] = {
|
||||
'name': city_name,
|
||||
if id_loc not in res.keys():
|
||||
res[id_loc] = {}
|
||||
accounts_id[id_loc] = {
|
||||
'name': id_loc,
|
||||
'sum_debit': [],
|
||||
'sum_credit': [],
|
||||
'balance': []
|
||||
}
|
||||
|
||||
if id_ not in res[id_city].keys():
|
||||
res[id_city][id_] = {
|
||||
if id_ not in res[id_loc].keys():
|
||||
res[id_loc][id_] = {
|
||||
'name': name,
|
||||
'id_number': id_number,
|
||||
'accounts': [],
|
||||
}
|
||||
accounts_id[id_city][id_] = {}
|
||||
accounts_id[id_loc][id_] = {}
|
||||
|
||||
if account_id not in accounts_id[id_city][id_].keys():
|
||||
accounts_id[id_city][id_][account_id] = {
|
||||
if account_id not in accounts_id[id_loc][id_].keys():
|
||||
accounts_id[id_loc][id_][account_id] = {
|
||||
'account': line.account,
|
||||
'lines': [],
|
||||
'sum_debit': [],
|
||||
'sum_credit': [],
|
||||
'balance': []
|
||||
}
|
||||
res[id_city][id_]['accounts'].append(account_id)
|
||||
res[id_loc][id_]['accounts'].append(account_id)
|
||||
|
||||
accounts_id[id_city][id_][account_id]['lines'].append(line)
|
||||
accounts_id[id_city][id_][account_id]['sum_debit'].append(line.debit)
|
||||
accounts_id[id_city][id_][account_id]['sum_credit'].append(line.credit)
|
||||
accounts_id[id_city][id_][account_id]['balance'].append(line.debit - line.credit)
|
||||
accounts_id[id_city]['sum_debit'].append(line.debit)
|
||||
accounts_id[id_city]['sum_credit'].append(line.credit)
|
||||
accounts_id[id_city]['balance'].append(line.debit - line.credit)
|
||||
accounts_id[id_loc][id_][account_id]['lines'].append(line)
|
||||
accounts_id[id_loc][id_][account_id]['sum_debit'].append(line.debit)
|
||||
accounts_id[id_loc][id_][account_id]['sum_credit'].append(line.credit)
|
||||
accounts_id[id_loc][id_][account_id]['balance'].append(line.debit - line.credit)
|
||||
accounts_id[id_loc]['sum_debit'].append(line.debit)
|
||||
accounts_id[id_loc]['sum_credit'].append(line.credit)
|
||||
accounts_id[id_loc]['balance'].append(line.debit - line.credit)
|
||||
else:
|
||||
if id_ not in res.keys():
|
||||
res[id_] = {
|
||||
|
@ -1673,12 +1685,10 @@ class AuxiliaryParty(Report):
|
|||
accounts_id[id_][account_id]['sum_debit'].append(line.debit)
|
||||
accounts_id[id_][account_id]['sum_credit'].append(line.credit)
|
||||
accounts_id[id_][account_id]['balance'].append(line.debit - line.credit)
|
||||
# print('records', res)
|
||||
# print('aconuts', account_id)
|
||||
report_context['_records'] = res
|
||||
report_context['_accounts'] = accounts_id
|
||||
report_context['grouped_by_account'] = data['grouped_by_account']
|
||||
report_context['grouped_by_location'] = data['grouped_by_location']
|
||||
report_context['grouped_by_location'] = grouped_by_loc
|
||||
report_context['start_period'] = start_period.name if start_period else '*'
|
||||
report_context['end_period'] = end_period.name if end_period else '*'
|
||||
report_context['company'] = company
|
||||
|
|
40
invoice.py
40
invoice.py
|
@ -3,7 +3,6 @@
|
|||
from sql import Table
|
||||
from decimal import Decimal
|
||||
from datetime import date, timedelta
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelView, ModelSQL, fields, dualmethod
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
|
@ -15,7 +14,7 @@ from trytond.exceptions import UserError
|
|||
|
||||
from .exceptions import (
|
||||
NotificationAuthError, NotificationAuthWarning, InvalidTypeInvoiceError,
|
||||
)
|
||||
)
|
||||
|
||||
conversor = None
|
||||
try:
|
||||
|
@ -98,27 +97,14 @@ class Invoice(metaclass=PoolMeta):
|
|||
# })
|
||||
cls.payment_term.states['required'] = True
|
||||
cls.payment_term.states['readonly'] = Eval('state') == 'posted'
|
||||
cls._buttons.update({
|
||||
'validate_taxes_wizard': {}
|
||||
})
|
||||
|
||||
def print_invoice(self):
|
||||
# Ignore cache for invoice because high demand of resources
|
||||
return
|
||||
|
||||
# Esto no es una buena idea porque
|
||||
# Una empresa puede manejar muchas autorizaciones
|
||||
# @fields.depends('invoice_type', 'authorization', 'company')
|
||||
# def on_change_with_authorization(self):
|
||||
# Authorization = Pool().get('account.invoice.authorization')
|
||||
# _invoice_type = '1' if self.invoice_type == '2' else self.invoice_type
|
||||
# auths = Authorization.search([
|
||||
# ('company', '=', self.company.id),
|
||||
# ('state', '=', 'active'),
|
||||
# ('kind', '=', _invoice_type)
|
||||
# ])
|
||||
# if auths:
|
||||
# return auths[0].id
|
||||
# else:
|
||||
# return None
|
||||
|
||||
@classmethod
|
||||
def copy(cls, invoices, default=None):
|
||||
if default is None:
|
||||
|
@ -164,14 +150,30 @@ class Invoice(metaclass=PoolMeta):
|
|||
@classmethod
|
||||
@ModelView.button
|
||||
def validate_invoice(cls, invoices):
|
||||
super(Invoice, cls).validate_invoice(invoices)
|
||||
for inv in invoices:
|
||||
if inv.type == 'out' and inv.invoice_type in ['', None]:
|
||||
raise InvalidTypeInvoiceError(
|
||||
gettext('account_col.msg_invalid_type_invoice')
|
||||
)
|
||||
else:
|
||||
cls.validate_tax(inv)
|
||||
cls.set_number([inv])
|
||||
super(Invoice, cls).validate_invoice(invoices)
|
||||
|
||||
@classmethod
|
||||
def validate_tax(cls, invoice):
|
||||
pool = Pool()
|
||||
Config = pool.get('account.configuration')
|
||||
Line = pool.get('account.invoice.line')
|
||||
InvoiceTax = Pool().get('account.invoice.tax')
|
||||
config = Config(1)
|
||||
taxes_validate = [t for t in invoice.taxes if t.base and t.tax.base and t.tax.base > t.base]
|
||||
if taxes_validate and config.remove_tax:
|
||||
lines_to_change = [l for l in invoice.lines if l.type == 'line']
|
||||
Line.write(lines_to_change, {'taxes': [
|
||||
('remove', [t.tax.id for t in taxes_validate])]})
|
||||
InvoiceTax.delete(taxes_validate)
|
||||
invoice.save()
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
|
|
2
tax.py
2
tax.py
|
@ -59,6 +59,7 @@ class Tax(metaclass=PoolMeta):
|
|||
('autorenta', 'autorenta'),
|
||||
], 'Classification Tax Electronic Invoice')
|
||||
not_printable = fields.Boolean('Not Printable')
|
||||
base = fields.Numeric('Base', digits=(16, 2))
|
||||
|
||||
|
||||
class TaxLine(metaclass=PoolMeta):
|
||||
|
@ -236,7 +237,6 @@ class PrintTaxesPosted(Wizard):
|
|||
taxes = None
|
||||
if self.start.taxes:
|
||||
taxes = [tax.id for tax in self.start.taxes]
|
||||
print('tax selected', taxes)
|
||||
data = {
|
||||
'company': self.start.company.id,
|
||||
'fiscalyear': self.start.fiscalyear.id,
|
||||
|
|
|
@ -7,6 +7,8 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="equivalent_invoice_sec"/>
|
||||
</xpath>
|
||||
<xpath expr="/form/field[@name='tax_rounding']" position="after">
|
||||
<label name="remove_tax"/>
|
||||
<field name="remove_tax"/>
|
||||
<label name="template_email_confirm"/>
|
||||
<field name="template_email_confirm"/>
|
||||
</xpath>
|
||||
|
|
10
view/invoice_validate_taxes_start_view_form.xml
Normal file
10
view/invoice_validate_taxes_start_view_form.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="description"/>
|
||||
<field name="description"/>
|
||||
<label name="tax"/>
|
||||
<field name="tax"/>
|
||||
|
||||
</form>
|
|
@ -10,18 +10,20 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="start_period"/>
|
||||
<label name="end_period"/>
|
||||
<field name="end_period"/>
|
||||
<label name="empty_account"/>
|
||||
<field name="empty_account"/>
|
||||
<label name="posted"/>
|
||||
<field name="posted"/>
|
||||
<label name="grouped_by_location"/>
|
||||
<field name="grouped_by_location"/>
|
||||
<label name="reference"/>
|
||||
<field name="reference"/>
|
||||
<label name="only_reference"/>
|
||||
<field name="only_reference"/>
|
||||
<label name="grouped_by_account"/>
|
||||
<field name="grouped_by_account"/>
|
||||
<group colspan="6" col="-1" id="checkboxes">
|
||||
<label name="empty_account"/>
|
||||
<field name="empty_account" xexpand="0" width="25"/>
|
||||
<label name="posted"/>
|
||||
<field name="posted" xexpand="0" width="25"/>
|
||||
<label name="grouped_by_location"/>
|
||||
<field name="grouped_by_location" xexpand="0" width="25"/>
|
||||
<label name="only_reference"/>
|
||||
<field name="only_reference" xexpand="0" width="25"/>
|
||||
<label name="grouped_by_account"/>
|
||||
<field name="grouped_by_account" xexpand="0" width="25"/>
|
||||
</group>
|
||||
<newline/>
|
||||
<field name="accounts" colspan="4"/>
|
||||
</form>
|
||||
|
|
|
@ -6,6 +6,8 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<xpath
|
||||
expr="/form/notebook/page[@id='general']/group[@id='amount_rate']"
|
||||
position="after">
|
||||
<label name="base"/>
|
||||
<field name="base"/>
|
||||
<label name="classification"/>
|
||||
<field name="classification"/>
|
||||
<label name="classification_tax"/>
|
||||
|
|
Loading…
Reference in a new issue