first commit
This commit is contained in:
55
sale.py
Normal file
55
sale.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pyson import Eval
|
||||
|
||||
from trytond.exceptions import UserError
|
||||
|
||||
class Sale(metaclass=PoolMeta):
|
||||
'Sale Analytic Operation'
|
||||
__name__ = 'sale.sale'
|
||||
|
||||
account_analytic = fields.Many2One('analytic_account.account',
|
||||
'Analytic Account',
|
||||
domain=[
|
||||
('type', '=', 'normal'),
|
||||
])
|
||||
class SaleLine(metaclass=PoolMeta):
|
||||
'Sale Line Analytic Operation'
|
||||
__name__ = 'sale.line'
|
||||
|
||||
|
||||
|
||||
@fields.depends('product', 'unit', 'sale',
|
||||
'_parent_sale.party', '_parent_sale.invoice_party',
|
||||
'_parent_sale.account_analytic', 'analytic_accounts',
|
||||
methods=['compute_taxes', 'compute_unit_price',
|
||||
'on_change_with_amount'])
|
||||
def on_change_product(self):
|
||||
if not self.product:
|
||||
return
|
||||
|
||||
party = None
|
||||
if self.sale:
|
||||
party = self.sale.invoice_party or self.sale.party
|
||||
|
||||
# Set taxes before unit_price to have taxes in context of sale price
|
||||
self.taxes = self.compute_taxes(party)
|
||||
|
||||
category = self.product.sale_uom.category
|
||||
if not self.unit or self.unit.category != category:
|
||||
self.unit = self.product.sale_uom
|
||||
|
||||
self.unit_price = self.compute_unit_price()
|
||||
|
||||
|
||||
self.type = 'line'
|
||||
self.amount = self.on_change_with_amount()
|
||||
|
||||
self.analytic_accounts = tuple()
|
||||
try:
|
||||
self.analytic_accounts += ({'root': self.sale.account_analytic.root,
|
||||
'account': self.sale.account_analytic},)
|
||||
except:
|
||||
pass
|
||||
Reference in New Issue
Block a user