27.03.26
This commit is contained in:
@@ -6,6 +6,12 @@ from trytond.pool import PoolMeta
|
||||
class Invoice(metaclass=PoolMeta):
|
||||
__name__ = 'account.invoice'
|
||||
|
||||
def _get_report_invoice_line(self):
|
||||
for line in self.lines or []:
|
||||
if getattr(line, 'type', None) == 'line':
|
||||
return line
|
||||
return self.lines[0] if self.lines else None
|
||||
|
||||
def _get_report_purchase(self):
|
||||
purchases = list(self.purchases or [])
|
||||
return purchases[0] if purchases else None
|
||||
@@ -128,6 +134,41 @@ class Invoice(metaclass=PoolMeta):
|
||||
return trade.report_price
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_rate_currency_upper(self):
|
||||
line = self._get_report_invoice_line()
|
||||
if line:
|
||||
return line.report_rate_currency_upper
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_rate_value(self):
|
||||
line = self._get_report_invoice_line()
|
||||
if line:
|
||||
return line.report_rate_value
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_rate_unit_upper(self):
|
||||
line = self._get_report_invoice_line()
|
||||
if line:
|
||||
return line.report_rate_unit_upper
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_rate_price_words(self):
|
||||
line = self._get_report_invoice_line()
|
||||
if line:
|
||||
return line.report_rate_price_words
|
||||
return self.report_price or ''
|
||||
|
||||
@property
|
||||
def report_rate_pricing_text(self):
|
||||
line = self._get_report_invoice_line()
|
||||
if line:
|
||||
return line.report_rate_pricing_text
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_payment_date(self):
|
||||
trade = self._get_report_trade()
|
||||
@@ -165,7 +206,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
line = self._get_report_trade_line()
|
||||
if line and line.lots:
|
||||
return sum(
|
||||
lot.get_current_gross_quantity_converted()
|
||||
lot.get_current_gross_quantity()
|
||||
for lot in line.lots if lot.lot_type == 'physic'
|
||||
)
|
||||
return ''
|
||||
@@ -178,7 +219,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
line = self._get_report_trade_line()
|
||||
if line and line.lots:
|
||||
return sum(
|
||||
lot.get_current_quantity_converted()
|
||||
lot.get_current_quantity()
|
||||
for lot in line.lots if lot.lot_type == 'physic'
|
||||
)
|
||||
if self.lines:
|
||||
@@ -190,7 +231,7 @@ class Invoice(metaclass=PoolMeta):
|
||||
net = self.report_net
|
||||
if net == '':
|
||||
return ''
|
||||
return Decimal(net) * Decimal('2.20462')
|
||||
return round(Decimal(net) * Decimal('2204.62'),2)
|
||||
|
||||
@property
|
||||
def report_bl_date(self):
|
||||
@@ -285,6 +326,9 @@ class InvoiceLine(metaclass=PoolMeta):
|
||||
return None
|
||||
return getattr(origin, 'sale', None) or getattr(origin, 'purchase', None)
|
||||
|
||||
def _get_report_trade_line(self):
|
||||
return getattr(self, 'origin', None)
|
||||
|
||||
@property
|
||||
def report_product_description(self):
|
||||
if self.product:
|
||||
@@ -298,6 +342,38 @@ class InvoiceLine(metaclass=PoolMeta):
|
||||
def report_description_upper(self):
|
||||
return (self.description or '').upper()
|
||||
|
||||
@property
|
||||
def report_rate_currency_upper(self):
|
||||
origin = self._get_report_trade_line()
|
||||
currency = getattr(origin, 'linked_currency', None) or self.currency
|
||||
if currency and currency.rec_name:
|
||||
return currency.rec_name.upper()
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_rate_value(self):
|
||||
return self.unit_price if self.unit_price is not None else ''
|
||||
|
||||
@property
|
||||
def report_rate_unit_upper(self):
|
||||
origin = self._get_report_trade_line()
|
||||
unit = getattr(origin, 'linked_unit', None) or self.unit
|
||||
if unit and unit.rec_name:
|
||||
return unit.rec_name.upper()
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_rate_price_words(self):
|
||||
trade = self._get_report_trade()
|
||||
if trade and getattr(trade, 'report_price', None):
|
||||
return trade.report_price
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_rate_pricing_text(self):
|
||||
origin = self._get_report_trade_line()
|
||||
return getattr(origin, 'get_pricing_text', '') or ''
|
||||
|
||||
@property
|
||||
def report_crop_name(self):
|
||||
trade = self._get_report_trade()
|
||||
|
||||
@@ -214,19 +214,19 @@ class Lot(metaclass=PoolMeta):
|
||||
if self.sale_line:
|
||||
return self.sale_line.sale.id
|
||||
|
||||
class Sale(metaclass=PoolMeta):
|
||||
__name__ = 'sale.sale'
|
||||
|
||||
btb = fields.Many2One('back.to.back',"Back to back")
|
||||
bank_accounts = fields.Function(
|
||||
fields.Many2Many('bank.account', None, None, "Bank Accounts"),
|
||||
'on_change_with_bank_accounts')
|
||||
bank_account = fields.Many2One(
|
||||
'bank.account', "Bank Account",
|
||||
domain=[('id', 'in', Eval('bank_accounts', []))],
|
||||
depends=['bank_accounts'])
|
||||
from_location = fields.Many2One('stock.location', 'From location', required=True,domain=[('type', "!=", 'customer')])
|
||||
to_location = fields.Many2One('stock.location', 'To location', required=True,domain=[('type', "!=", 'supplier')])
|
||||
class Sale(metaclass=PoolMeta):
|
||||
__name__ = 'sale.sale'
|
||||
|
||||
btb = fields.Many2One('back.to.back',"Back to back")
|
||||
bank_accounts = fields.Function(
|
||||
fields.Many2Many('bank.account', None, None, "Bank Accounts"),
|
||||
'on_change_with_bank_accounts')
|
||||
bank_account = fields.Many2One(
|
||||
'bank.account', "Bank Account",
|
||||
domain=[('id', 'in', Eval('bank_accounts', []))],
|
||||
depends=['bank_accounts'])
|
||||
from_location = fields.Many2One('stock.location', 'From location', required=True,domain=[('type', "!=", 'customer')])
|
||||
to_location = fields.Many2One('stock.location', 'To location', required=True,domain=[('type', "!=", 'supplier')])
|
||||
shipment_out = fields.Many2One('stock.shipment.out','Sales')
|
||||
#pnl = fields.One2Many('valuation.valuation', 'sale', 'Pnl')
|
||||
pnl = fields.One2Many('valuation.valuation.dyn', 'r_sale', 'Pnl',states={'invisible': ~Eval('group_pnl'),})
|
||||
@@ -256,47 +256,47 @@ class Sale(metaclass=PoolMeta):
|
||||
trader = fields.Many2One('party.party',"Trader")
|
||||
operator = fields.Many2One('party.party',"Operator")
|
||||
our_reference = fields.Char("Our Reference")
|
||||
company_visible = fields.Function(
|
||||
fields.Boolean("Visible"), 'on_change_with_company_visible')
|
||||
lc_date = fields.Date("LC date")
|
||||
product_origin = fields.Char("Origin")
|
||||
|
||||
@fields.depends('company', '_parent_company.party')
|
||||
def on_change_with_company_visible(self, name=None):
|
||||
return bool(
|
||||
self.company and self.company.party
|
||||
and self.company.party.name == 'MELYA')
|
||||
|
||||
def _get_default_bank_account(self):
|
||||
if not self.party or not self.party.bank_accounts:
|
||||
return None
|
||||
party_bank_accounts = list(self.party.bank_accounts)
|
||||
if self.currency:
|
||||
for account in party_bank_accounts:
|
||||
if account.currency == self.currency:
|
||||
return account
|
||||
return party_bank_accounts[0]
|
||||
|
||||
@fields.depends('party', '_parent_party.bank_accounts')
|
||||
def on_change_with_bank_accounts(self, name=None):
|
||||
if self.party and self.party.bank_accounts:
|
||||
return [account.id for account in self.party.bank_accounts]
|
||||
return []
|
||||
|
||||
@fields.depends(
|
||||
'company', 'party', 'invoice_party', 'shipment_party', 'warehouse',
|
||||
'payment_term', 'lines', 'bank_account', '_parent_party.bank_accounts')
|
||||
def on_change_party(self):
|
||||
super().on_change_party()
|
||||
self.bank_account = self._get_default_bank_account()
|
||||
|
||||
@fields.depends('party', 'currency', '_parent_party.bank_accounts')
|
||||
def on_change_currency(self):
|
||||
self.bank_account = self._get_default_bank_account()
|
||||
|
||||
@classmethod
|
||||
def default_wb(cls):
|
||||
WB = Pool().get('purchase.weight.basis')
|
||||
company_visible = fields.Function(
|
||||
fields.Boolean("Visible"), 'on_change_with_company_visible')
|
||||
lc_date = fields.Date("LC date")
|
||||
product_origin = fields.Char("Origin")
|
||||
|
||||
@fields.depends('company', '_parent_company.party')
|
||||
def on_change_with_company_visible(self, name=None):
|
||||
return bool(
|
||||
self.company and self.company.party
|
||||
and self.company.party.name == 'MELYA')
|
||||
|
||||
def _get_default_bank_account(self):
|
||||
if not self.party or not self.party.bank_accounts:
|
||||
return None
|
||||
party_bank_accounts = list(self.party.bank_accounts)
|
||||
if self.currency:
|
||||
for account in party_bank_accounts:
|
||||
if account.currency == self.currency:
|
||||
return account
|
||||
return party_bank_accounts[0]
|
||||
|
||||
@fields.depends('party', '_parent_party.bank_accounts')
|
||||
def on_change_with_bank_accounts(self, name=None):
|
||||
if self.party and self.party.bank_accounts:
|
||||
return [account.id for account in self.party.bank_accounts]
|
||||
return []
|
||||
|
||||
@fields.depends(
|
||||
'company', 'party', 'invoice_party', 'shipment_party', 'warehouse',
|
||||
'payment_term', 'lines', 'bank_account', '_parent_party.bank_accounts')
|
||||
def on_change_party(self):
|
||||
super().on_change_party()
|
||||
self.bank_account = self._get_default_bank_account()
|
||||
|
||||
@fields.depends('party', 'currency', '_parent_party.bank_accounts')
|
||||
def on_change_currency(self):
|
||||
self.bank_account = self._get_default_bank_account()
|
||||
|
||||
@classmethod
|
||||
def default_wb(cls):
|
||||
WB = Pool().get('purchase.weight.basis')
|
||||
wb = WB.search(['id','>',0])
|
||||
if wb:
|
||||
return wb[0].id
|
||||
@@ -333,14 +333,14 @@ class Sale(metaclass=PoolMeta):
|
||||
@property
|
||||
def report_gross(self):
|
||||
if self.lines:
|
||||
return sum([l.get_current_gross_quantity_converted() for l in self.lines[0].lots if l.lot_type == 'physic'])
|
||||
return sum([l.get_current_gross_quantity() for l in self.lines[0].lots if l.lot_type == 'physic'])
|
||||
else:
|
||||
return ''
|
||||
|
||||
@property
|
||||
def report_net(self):
|
||||
if self.lines:
|
||||
return sum([l.get_current_quantity_converted() for l in self.lines[0].lots if l.lot_type == 'physic'])
|
||||
return sum([l.get_current_quantity() for l in self.lines[0].lots if l.lot_type == 'physic'])
|
||||
else:
|
||||
return ''
|
||||
|
||||
|
||||
Reference in New Issue
Block a user