TAXES

Taxes are defined by the model `*account.tax* <http://hg.tryton.org/modules/account/file/3.2/tax.py#l568>`_.

TAXES ON PRODUCTS

Default taxes for a product need to be defined on the product template `*product.template* <http://hg.tryton.org/modules/account_product/file/3.2/product.py#l163>`_. The field *customer_taxes* defines the default taxes that will be used on the sale. If the field *taxes_category* is set to *True* the default taxes that are set on the product category will be used.

TAX RULES

For customers that are located in a different country than the company that is using Tryton the default tax on the product must be replaced by another tax. This is done by tax rules. A tax rule is a set of rules that need to be applied to the default tax on the product. For the moment it seems that there are no tax rules defined by default in a Tryton-to-go database.

TAX RULES ON A PARTY

For customers that are located in a different country than the company that is using Tryton a tax rule must be assigned to the party.
The field *customer_tax_rule* on model `*party.party* <http://hg.tryton.org/modules/account/file/3.2/party.py#l17>`_ defines the rule that will be used to calculate the taxes to use on the sale.

TAXES ON A SALE

The Tryton client uses a special feature of the framework to calculate the tax to use on a sale line.
In the Tryton client the change of the value on the field *product* on the model `*sale.line* <http://hg.tryton.org/modules/sale/file/3.2/sale.py#l964>`_ triggers a so called *on_change*-Event in the Tryton client.
This means that the Tryton Client will call the method `*on_change_product()* <http://hg.tryton.org/modules/sale/file/3.2/sale.py#l1163>`_ on such an event. This is not done directly but by a call to *on_change()*,

As you can see on the `method decorator <http://hg.tryton.org/modules/sale/file/3.2/sale.py#l1163>`_ the call to on_change_product does have some dependencies for field field values that must be available on the call.

First you must know about the value dependencies for the call of *on_change()*.
You can get this information by a request to the method `*fields_view_get()* <http://hg.tryton.org/trytond/file/3.2/trytond/model/modelview.py#l107>`_

This is an example for an request to *fields_vew_get()* for the model *sale.line*::

{
"id": 1,
"method":"model.sale.line.fields_view_get",
"params":[userid, sessionid, None, 'form', context]
}

If you look at the results of this request you will find the information about the product field at this key: result['fields']['product']
The value dependencies for the call of *on_change_product* are defined at this key: result['fields']['product']['on_change']

These are the values of the key on a basic Tryton-to-go instance::

[

'product',
'_parent_sale.currency',
'description',
'discount',
'_parent_sale.sale_date',
'_parent_sale.party',
'unit',
'quantity'

]

This means that at least the values of these fields must be added to a request to model.sale.line.on_change_product().

The field types of all fields not starting with '_parent_' can be taken from the result for the call to model.sale.line.fields_view_get() too. You can find this informationen at the key: result['fields'][FIELDNAME]['type'] (replace FIELDNAME with a field name of the model sale.line)

For the fields prefixed with '_parent_' this means that the value of a field on a relation is needed. First strip the '_parent_' and get the information about this field. And then you need to request the information about the relation. Let's take the example '_parent_sale.sale_date'.

This is the part of the request to model.sale.line.fields_view_get() the describes the field 'sale' (key: result['fields']['sale']):

{
    'context': u'{}',
    'create': True,
    'delete': True,
    'domain': u'[]',
    'help': u'',
    'loading': u'eager',
    'name': u'sale',
    'on_change': [],
    'on_change_with': [],
    'readonly': False,
    'relation': u'sale.sale',
    'relation_field': u'lines',
    'required': False,
    'searchable': True,
    'select': True,
    'states': u'{}',
    'string': u'Verkauf',
    'type': u'many2one',
    'views': {}

The value of key type describes this field as a many2one field. This means this field is a n:1-Relation to another model. The value of key relation names the related model. In our case this is the model sale.sale. So if you want to know which field type the field '_parent_sale.sale_date' has you need to make a call to model.sale.sale.fields_view_get(). You will find the description for the field 'sale_date' there.

Here is a big difference between the Tryton Version 3.2 (current version used by tryton.cloud) and the future Version 4.0. 


Calling *on_change_product* in Tryton Version 3.2

This is an example for an request to *model.sale.line.on_change_product()*::

{

"id": 1,
"method":"model.sale.line.on_change_product",
"params":[

userid,
sessionid, {
'product': 3,

'_parent_sale.currency': 24,
'description': '',
'_parent_sale.sale_date': None,
'discount': None,
_parent_sale.party': 18,
'unit': None,
'quantity': None

},
context

]

}

This is an example of a result of this request::

{

'unit_digits': 2,
'unit.rec_name': 'Stunde(n)',
'unit_price': Decimal('120.0000'),
'amount': Decimal('0.00'),
'taxes': [2], # This is a list of ids of model *account.tax*
'unit': 9, # This is an id for an record of model *product.uom*
'description': 'Erstellung von Sitzungsrapporten und weiterer Korrespondenz.'

}

 

Calling *on_change_product* in Tryton Version 4.0

This is an example for an request to *model.sale.line.on_change_product()* which is made indirectly by a call to *model.sale.line.on_change()*::

{

"id": 1,
"method":"model.sale.line.on_change",
"params":[

userid,
sessionid, {

'product': 3,
'_parent_sale.currency': 24,
'description': '',
'_parent_sale.sale_date': None,
'discount': None,
_parent_sale.party': 18,
'unit': None,
'quantity': None

},
['product'], # This is a list of on_change methods that will be called
context

]

}

The result of this request is identical to the result of Tryton Version 3.2