trytond-sale_cost_apply_inv.../sale_cost.py

61 lines
2.0 KiB
Python

# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import PoolMeta
from trytond.model import fields
from trytond.pyson import Eval, Or, Not, Bool
from trytond.modules.document_cost_apply_invoice.cost import (
ApplyMethodCostMixin, ApplyMethodCostDocumentMixin)
__all__ = ['CostType', 'CostTemplate', 'SaleCost']
class CostType(ApplyMethodCostMixin, metaclass=PoolMeta):
__name__ = 'sale.cost.type'
class CostTemplate(metaclass=PoolMeta):
__name__ = 'sale.cost.template'
invoice_party = fields.Many2One('party.party', 'Invoice Party',
states={
'invisible': ~Eval('apply_method', '').in_(
['invoice_in', 'invoice_out'])
}, depends=['apply_method'])
def on_change_type_(self):
super(CostTemplate, self).on_change_type_()
if self.type_:
self.invoice_party = self.type_.invoice_party
class SaleCost(ApplyMethodCostDocumentMixin, metaclass=PoolMeta):
__name__ = 'sale.cost'
def on_change_template(self):
super(SaleCost, self).on_change_template()
if self.template:
self.invoice_party = self.template.invoice_party
def on_change_type_(self):
super(SaleCost, self).on_change_type_()
if self.type_:
self.invoice_party = self.type_.invoice_party
@classmethod
def __setup__(cls):
super().__setup__()
invisible_condition = cls._buttons['apply']['invisible']
cls._buttons['apply']['invisible'] = Or(
invisible_condition,
Bool(Eval('invoice_lines')))
cls._buttons['apply']['depends'].append('invoice_lines')
invisible_condition = cls._buttons['unapply']['invisible']
cls._buttons['unapply']['invisible'] = Or(
invisible_condition,
Not(Bool(Eval('invoice_lines'))))
cls._buttons['unapply']['depends'].append('invoice_lines')
@property
def non_explodable(self):
return super().non_explodable or bool(self.invoice_lines)