Allows exclude shipment lines of computation of costs of payment type when compute is without taxes

This commit is contained in:
jmartin 2015-03-27 12:50:17 +01:00
parent 7857b01586
commit f2424f678c
6 changed files with 71 additions and 4 deletions

View File

@ -3,9 +3,11 @@
# copyright notices and license terms.
from trytond.pool import Pool
from sale import *
from payment_type import *
def register():
Pool.register(
Sale,
PaymentType,
module='sale_payment_type_cost', type_='model')

30
payment_type.py Normal file
View File

@ -0,0 +1,30 @@
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.model import fields
from trytond.pool import PoolMeta
from trytond.pyson import Bool, Eval
__all__ = ['PaymentType']
__metaclass__ = PoolMeta
class PaymentType:
__name__ = 'account.payment.type'
exclude_shipment_lines = fields.Boolean('Exclude Shipment Lines',
states={
'invisible': Bool(Eval('compute_over_total_amount')),
},
help='Excludes the shipment lines of computation of costs of this '
'payment type.')
@fields.depends('compute_over_total_amount')
def on_change_compute_over_total_amount(self):
try:
res = super(PaymentType,
self).on_change_compute_over_total_amount()
except AttributeError:
res = {}
if self.compute_over_total_amount:
res['exclude_shipment_lines'] = False
return res

14
payment_type.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<tryton>
<data>
<!-- account.payment.type -->
<record model="ir.ui.view" id="account_payment_type_view_form">
<field name="model">account.payment.type</field>
<field name="name">payment_type_form</field>
<field name="inherit"
ref="account_payment_type.account_payment_type_view_form"/>
</record>
</data>
</tryton>

12
sale.py
View File

@ -47,9 +47,13 @@ class Sale:
continue
setattr(line, key, value)
if self.payment_type.compute_over_total_amount:
line.unit_price = (self.total_amount *
self.payment_type.cost_percent)
amount = self.total_amount
elif self.payment_type.exclude_shipment_lines:
amount = sum([l.amount
for l in self.lines
if not getattr(l, 'shipment_cost', False)
])
else:
line.unit_price = (self.untaxed_amount *
self.payment_type.cost_percent)
amount = self.untaxed_amount
line.unit_price = (amount * self.payment_type.cost_percent)
return line

View File

@ -3,3 +3,7 @@ version=3.4.0
depends:
sale_payment_type
account_payment_type_cost
extras_depend:
sale_shipment_cost
xml:
payment_type.xml

View File

@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!-- The COPYRIGHT file at the top level of this repository contains the full
copyright notices and license terms. -->
<data>
<xpath expr="/form/group[@id='costs']" position="replace_attributes">
<group id="costs" colspan="4" col="10"/>
</xpath>
<xpath expr="/form/group/field[@name='compute_over_total_amount']"
position="after">
<label name="exclude_shipment_lines"/>
<field name="exclude_shipment_lines"/>
</xpath>
</data>