Fix invoice amount searchers and payment methods view
This commit is contained in:
+43
-53
@@ -3,6 +3,10 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from decimal import Decimal
|
||||
from datetime import date
|
||||
from sql.aggregate import Sum
|
||||
from sql.conditionals import Coalesce
|
||||
from sql.functions import Round
|
||||
from trytond import backend
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval, If, And
|
||||
@@ -175,7 +179,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
"CDT Invoiced", currency='currency', digits='currency',
|
||||
states={
|
||||
'invisible': ~Eval('cdt_invoiced', 0),
|
||||
}), 'on_change_with_cdt_invoiced', searcher='search_cdt_invoiced ')
|
||||
}), 'on_change_with_cdt_invoiced', searcher='search_cdt_invoiced')
|
||||
|
||||
isr_withholding = fields.Function(Monetary(
|
||||
"ISR Withholding", currency='currency', digits='currency',
|
||||
@@ -1021,36 +1025,51 @@ class Invoice(metaclass=PoolMeta):
|
||||
|
||||
@classmethod
|
||||
def search_amount_invoiced_services(cls, name, clause):
|
||||
return cls._search_amount_invoiced_by_product_type(
|
||||
name, clause, 'service')
|
||||
|
||||
@classmethod
|
||||
def search_amount_invoiced_goods(cls, name, clause):
|
||||
return cls._search_amount_invoiced_by_product_type(
|
||||
name, clause, 'goods')
|
||||
|
||||
@classmethod
|
||||
def _search_amount_invoiced_by_product_type(
|
||||
cls, name, clause, product_type):
|
||||
pool = Pool()
|
||||
Rule = pool.get('ir.rule')
|
||||
Line = pool.get('account.invoice.line')
|
||||
Invoice = pool.get('account.invoice')
|
||||
Currency = pool.get('currency.currency')
|
||||
type_name = cls.amount_invoiced_services._field.sql_type().base
|
||||
Product = pool.get('product.product')
|
||||
Template = pool.get('product.template')
|
||||
type_name = getattr(cls, name)._field.sql_type().base
|
||||
line = Line.__table__()
|
||||
invoice = Invoice.__table__()
|
||||
currency = Currency.__table__()
|
||||
product = Product.__table__()
|
||||
template = Template.__table__()
|
||||
|
||||
_, operator, value = clause
|
||||
invoice_query = Rule.query_get('account.invoice')
|
||||
Operator = fields.SQL_OPERATORS[operator]
|
||||
# SQLite uses float for sum
|
||||
if backend.name() == 'sqlite':
|
||||
if backend.name == 'sqlite':
|
||||
value = float(value)
|
||||
|
||||
query = line.join(invoice,
|
||||
condition=(invoice.id == line.invoice)
|
||||
).join(currency,
|
||||
condition=(currency.id == invoice.currency)
|
||||
).select(line.invoice,
|
||||
where=line.invoice.in_(
|
||||
invoice_query),
|
||||
group_by=line.invoice,
|
||||
having=Operator(Coalesce(Sum(
|
||||
Round((line.quantity * line.unit_price).cast(
|
||||
type_name),
|
||||
currency.digits)), 0).cast(type_name),
|
||||
value))
|
||||
query = (line.join(invoice, condition=(invoice.id == line.invoice))
|
||||
.join(currency, condition=(currency.id == invoice.currency))
|
||||
.join(product, condition=(product.id == line.product))
|
||||
.join(template, condition=(template.id == product.template))
|
||||
.select(
|
||||
line.invoice,
|
||||
where=(line.invoice.in_(invoice_query)
|
||||
& (line.type == 'line')
|
||||
& (template.type == product_type)),
|
||||
group_by=line.invoice,
|
||||
having=Operator(Coalesce(Sum(
|
||||
Round((line.quantity * line.unit_price).cast(type_name),
|
||||
currency.digits)), 0).cast(type_name), value)))
|
||||
return [('id', 'in', query)]
|
||||
|
||||
@classmethod
|
||||
@@ -1176,7 +1195,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
invoice_query = Rule.query_get('account.invoice')
|
||||
Operator = fields.SQL_OPERATORS[operator]
|
||||
# SQLite uses float for sum
|
||||
if backend.name() == 'sqlite':
|
||||
if backend.name == 'sqlite':
|
||||
value = float(value)
|
||||
|
||||
query = tax.select(tax.invoice,
|
||||
@@ -1198,7 +1217,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
invoice_query = Rule.query_get('account.invoice')
|
||||
Operator = fields.SQL_OPERATORS[operator]
|
||||
# SQLite uses float for sum
|
||||
if backend.name() == 'sqlite':
|
||||
if backend.name == 'sqlite':
|
||||
value = float(value)
|
||||
|
||||
query = tax.select(tax.invoice,
|
||||
@@ -1220,7 +1239,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
invoice_query = Rule.query_get('account.invoice')
|
||||
Operator = fields.SQL_OPERATORS[operator]
|
||||
# SQLite uses float for sum
|
||||
if backend.name() == 'sqlite':
|
||||
if backend.name == 'sqlite':
|
||||
value = float(value)
|
||||
|
||||
query = tax.select(tax.invoice,
|
||||
@@ -1242,7 +1261,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
invoice_query = Rule.query_get('account.invoice')
|
||||
Operator = fields.SQL_OPERATORS[operator]
|
||||
# SQLite uses float for sum
|
||||
if backend.name() == 'sqlite':
|
||||
if backend.name == 'sqlite':
|
||||
value = float(value)
|
||||
|
||||
query = tax.select(tax.invoice,
|
||||
@@ -1264,7 +1283,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
invoice_query = Rule.query_get('account.invoice')
|
||||
Operator = fields.SQL_OPERATORS[operator]
|
||||
# SQLite uses float for sum
|
||||
if backend.name() == 'sqlite':
|
||||
if backend.name == 'sqlite':
|
||||
value = float(value)
|
||||
|
||||
query = tax.select(tax.invoice,
|
||||
@@ -1286,7 +1305,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
invoice_query = Rule.query_get('account.invoice')
|
||||
Operator = fields.SQL_OPERATORS[operator]
|
||||
# SQLite uses float for sum
|
||||
if backend.name() == 'sqlite':
|
||||
if backend.name == 'sqlite':
|
||||
value = float(value)
|
||||
|
||||
query = tax.select(tax.invoice,
|
||||
@@ -1298,37 +1317,8 @@ class Invoice(metaclass=PoolMeta):
|
||||
|
||||
@classmethod
|
||||
def search_amount_invoiced_services(cls, name, clause):
|
||||
pool = Pool()
|
||||
Rule = pool.get('ir.rule')
|
||||
Line = pool.get('account.invoice.line')
|
||||
Invoice = pool.get('account.invoice')
|
||||
Currency = pool.get('currency.currency')
|
||||
type_name = cls.amount_invoiced_services._field.sql_type().base
|
||||
line = Line.__table__()
|
||||
invoice = Invoice.__table__()
|
||||
currency = Currency.__table__()
|
||||
|
||||
_, operator, value = clause
|
||||
invoice_query = Rule.query_get('account.invoice')
|
||||
Operator = fields.SQL_OPERATORS[operator]
|
||||
# SQLite uses float for sum
|
||||
if backend.name() == 'sqlite':
|
||||
value = float(value)
|
||||
|
||||
query = line.join(invoice,
|
||||
condition=(invoice.id == line.invoice)
|
||||
).join(currency,
|
||||
condition=(currency.id == invoice.currency)
|
||||
).select(line.invoice,
|
||||
where=line.invoice.in_(
|
||||
invoice_query),
|
||||
group_by=line.invoice,
|
||||
having=Operator(Coalesce(Sum(
|
||||
Round((line.quantity * line.unit_price).cast(
|
||||
type_name),
|
||||
currency.digits)), 0).cast(type_name),
|
||||
value))
|
||||
return [('id', 'in', query)]
|
||||
return cls._search_amount_invoiced_by_product_type(
|
||||
name, clause, 'service')
|
||||
|
||||
@classmethod
|
||||
def _ncf_invoice_type(cls, invoice):
|
||||
|
||||
@@ -61,7 +61,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<label name="isr_withholding_type"/>
|
||||
<field name="isr_withholding_type"/>
|
||||
<newline/>
|
||||
<separator name="payment_methods" colspan="4"/>
|
||||
<separator id="payment_methods" colspan="4"/>
|
||||
<label name="payment_method"/>
|
||||
<field name="payment_method"/>
|
||||
<newline/>
|
||||
@@ -83,4 +83,4 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<newline/>
|
||||
</page>
|
||||
</xpath>
|
||||
</data>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user