Fee linked unit
This commit is contained in:
@@ -55,9 +55,24 @@ class Fee(ModelSQL,ModelView):
|
||||
('pay', 'PAY'),
|
||||
('rec', 'REC'),
|
||||
], "P/R", required=True)
|
||||
product = fields.Many2One('product.product',"Product", required=True, domain=[('type', '=', 'service')])
|
||||
price = fields.Numeric("Price",digits=(1,4))
|
||||
mode = fields.Selection([
|
||||
product = fields.Many2One('product.product',"Product", required=True, domain=[('type', '=', 'service')])
|
||||
price = fields.Numeric("Price",digits=(1,4))
|
||||
enable_linked_currency = fields.Boolean("Linked currencies")
|
||||
linked_price = fields.Numeric("Linked Price", digits='unit', states={
|
||||
'invisible': ~Eval('enable_linked_currency'),
|
||||
'required': Eval('enable_linked_currency'),
|
||||
}, depends=['enable_linked_currency'])
|
||||
linked_currency = fields.Many2One('currency.linked', "Linked Currency",
|
||||
states={
|
||||
'invisible': ~Eval('enable_linked_currency'),
|
||||
'required': Eval('enable_linked_currency'),
|
||||
}, depends=['enable_linked_currency'])
|
||||
linked_unit = fields.Many2One('product.uom', "Linked Unit",
|
||||
states={
|
||||
'invisible': ~Eval('enable_linked_currency'),
|
||||
'required': Eval('enable_linked_currency'),
|
||||
}, depends=['enable_linked_currency'])
|
||||
mode = fields.Selection([
|
||||
('lumpsum', 'Lump sum'),
|
||||
('perqt', 'Per qt'),
|
||||
('pprice', '% price'),
|
||||
@@ -129,6 +144,75 @@ class Fee(ModelSQL,ModelView):
|
||||
@classmethod
|
||||
def default_qt_state(cls):
|
||||
return None
|
||||
|
||||
def _get_linked_unit_factor(self):
|
||||
if not (self.enable_linked_currency and self.linked_currency):
|
||||
return None
|
||||
factor = Decimal(self.linked_currency.factor or 0)
|
||||
if not factor:
|
||||
return None
|
||||
unit_factor = Decimal(1)
|
||||
if self.linked_unit:
|
||||
source_unit = getattr(self, 'unit', None)
|
||||
if not source_unit:
|
||||
return factor
|
||||
Uom = Pool().get('product.uom')
|
||||
unit_factor = Decimal(str(
|
||||
Uom.compute_qty(source_unit, float(1), self.linked_unit) or 0))
|
||||
return factor * unit_factor
|
||||
|
||||
def _linked_to_fee_price(self, price):
|
||||
factor = self._get_linked_unit_factor()
|
||||
price = Decimal(price or 0)
|
||||
if not factor:
|
||||
return price
|
||||
return round(price * factor, 4)
|
||||
|
||||
def _fee_to_linked_price(self, price):
|
||||
factor = self._get_linked_unit_factor()
|
||||
price = Decimal(price or 0)
|
||||
if not factor:
|
||||
return price
|
||||
return round(price / factor, 4)
|
||||
|
||||
def _sync_price_from_linked(self):
|
||||
if (self.enable_linked_currency and self.linked_currency
|
||||
and self.linked_price is not None):
|
||||
self.price = self._linked_to_fee_price(self.linked_price)
|
||||
|
||||
@fields.depends(
|
||||
'enable_linked_currency', 'linked_currency', 'linked_unit',
|
||||
'linked_price', 'price', 'unit')
|
||||
def on_change_enable_linked_currency(self):
|
||||
if self.enable_linked_currency and self.price is not None:
|
||||
self.linked_price = self._fee_to_linked_price(self.price)
|
||||
self._sync_price_from_linked()
|
||||
|
||||
@fields.depends(
|
||||
'enable_linked_currency', 'linked_currency', 'linked_unit',
|
||||
'linked_price', 'unit')
|
||||
def on_change_linked_price(self):
|
||||
self._sync_price_from_linked()
|
||||
|
||||
@fields.depends(
|
||||
'enable_linked_currency', 'linked_currency', 'linked_unit',
|
||||
'linked_price', 'unit')
|
||||
def on_change_linked_currency(self):
|
||||
self._sync_price_from_linked()
|
||||
|
||||
@fields.depends(
|
||||
'enable_linked_currency', 'linked_currency', 'linked_unit',
|
||||
'linked_price', 'unit')
|
||||
def on_change_linked_unit(self):
|
||||
self._sync_price_from_linked()
|
||||
|
||||
@fields.depends(
|
||||
'enable_linked_currency', 'linked_currency', 'linked_unit',
|
||||
'price', 'unit')
|
||||
def on_change_price(self):
|
||||
if (self.enable_linked_currency and self.linked_currency
|
||||
and self.price is not None):
|
||||
self.linked_price = self._fee_to_linked_price(self.price)
|
||||
|
||||
@fields.depends('mode','unit')
|
||||
def on_change_with_packing_category(self, name=None):
|
||||
|
||||
@@ -294,8 +294,6 @@ class Lot(metaclass=PoolMeta):
|
||||
|
||||
@classmethod
|
||||
def default_lot_unit(cls):
|
||||
if is_itsa_company():
|
||||
return default_itsa_unit()
|
||||
default = getattr(super(), 'default_lot_unit', None)
|
||||
if default:
|
||||
return default()
|
||||
@@ -4599,9 +4597,10 @@ class LotInvoice(Wizard):
|
||||
val['lot_diff_quantity'] = Decimal(0)
|
||||
val['lot_diff_price'] = Decimal(0)
|
||||
val['lot_diff_amount'] = Decimal(0)
|
||||
val['lot_quantity'] = lot.get_current_quantity_converted()
|
||||
val['lot_price'] = lot.lot_price
|
||||
val['lot_amount'] = lot.get_current_quantity_converted() * lot.lot_price if lot.lot_price else Decimal(0)
|
||||
val['lot_quantity'] = lot.get_current_quantity_converted()
|
||||
val['sale_invoice_padding'] = lot.sale_invoice_padding
|
||||
val['lot_price'] = lot.lot_price
|
||||
val['lot_amount'] = lot.get_current_quantity_converted() * lot.lot_price if lot.lot_price else Decimal(0)
|
||||
if lot.invoice_line_prov:
|
||||
val['lot_diff_quantity'] = val['lot_quantity'] - Decimal(lot.invoice_line_prov.quantity)
|
||||
val['lot_diff_price'] = val['lot_price'] - Decimal(lot.invoice_line_prov.unit_price)
|
||||
@@ -4908,10 +4907,12 @@ class LotInvoicingLot(ModelView):
|
||||
lis = fields.Many2One('lot.invoice.start',"Invoicing")
|
||||
lot = fields.Many2One('lot.lot',"Lot")
|
||||
lot_name = fields.Char("Name",readonly=True)
|
||||
lot_state = fields.Many2One('lot.qt.type',"State")
|
||||
lot_quantity = fields.Numeric("Qt",digits='unit',readonly=True)
|
||||
lot_diff_quantity = fields.Numeric("Diff. qt",digits='unit',readonly=True)
|
||||
lot_unit = fields.Many2One('product.uom',"Unit",readonly=True)
|
||||
lot_state = fields.Many2One('lot.qt.type',"State")
|
||||
lot_quantity = fields.Numeric("Qt",digits='unit',readonly=True)
|
||||
sale_invoice_padding = fields.Numeric(
|
||||
"Padding", digits='lot_unit', readonly=True)
|
||||
lot_diff_quantity = fields.Numeric("Diff. qt",digits='unit',readonly=True)
|
||||
lot_unit = fields.Many2One('product.uom',"Unit",readonly=True)
|
||||
lot_price = fields.Numeric("Price",digits='unit',readonly=True)
|
||||
lot_diff_price = fields.Numeric("Diff. price",digits='unit',readonly=True)
|
||||
lot_currency = fields.Char("Curr")
|
||||
@@ -5007,6 +5008,7 @@ class LotWeighing(Wizard):
|
||||
val['lot_qt'] = lot.lot_qt
|
||||
val['lot_quantity'] = lot.lot_quantity
|
||||
val['lot_gross_quantity'] = lot.lot_gross_quantity
|
||||
val['sale_invoice_padding'] = lot.sale_invoice_padding
|
||||
val['lot_unit'] = lot.lot_unit.id
|
||||
val['lot_unit_line'] = lot.lot_unit_line.id
|
||||
lot_p.append(val)
|
||||
@@ -5083,6 +5085,8 @@ class LotWeighingLot(ModelView):
|
||||
lot_qt = fields.Integer("Qt")
|
||||
lot_quantity = fields.Numeric("Net weight",digits=(1,5),readonly=True)
|
||||
lot_gross_quantity = fields.Numeric("Gross weight",digits=(1,5),readonly=True)
|
||||
sale_invoice_padding = fields.Numeric(
|
||||
"Padding", digits='lot_unit_line', readonly=True)
|
||||
lot_unit = fields.Many2One('product.uom',"Unit",readonly=True)
|
||||
lot_unit_line = fields.Many2One('product.uom',"Unit",readonly=True)
|
||||
lot_quantity_new = fields.Numeric("New net weight",digits=(1,5))
|
||||
|
||||
@@ -322,7 +322,7 @@ class Purchase(metaclass=PoolMeta):
|
||||
fields.Many2Many('bank.account', None, None, "Bank Accounts"),
|
||||
'on_change_with_bank_accounts')
|
||||
bank_account = fields.Many2One(
|
||||
'bank.account', "Bank Account",
|
||||
'bank.account', "Supplier Bank Account",
|
||||
domain=[('id', 'in', Eval('bank_accounts', []))],
|
||||
depends=['bank_accounts'])
|
||||
our_bank_account = fields.Many2One(
|
||||
|
||||
@@ -283,7 +283,7 @@ class Sale(metaclass=PoolMeta):
|
||||
fields.Many2Many('bank.account', None, None, "Bank Accounts"),
|
||||
'on_change_with_bank_accounts')
|
||||
bank_account = fields.Many2One(
|
||||
'bank.account', "Bank Account",
|
||||
'bank.account', "Client Bank Account",
|
||||
domain=[('id', 'in', Eval('bank_accounts', []))],
|
||||
depends=['bank_accounts'])
|
||||
our_bank_account = fields.Many2One(
|
||||
|
||||
@@ -1568,6 +1568,25 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertEqual(fee.quantity, Decimal('3'))
|
||||
save.assert_not_called()
|
||||
|
||||
def test_fee_linked_price_updates_fee_price(self):
|
||||
'fee linked price converts to the accounting currency price'
|
||||
Fee = Pool().get('fee.fee')
|
||||
fee = Fee()
|
||||
fee.enable_linked_currency = True
|
||||
fee.linked_price = Decimal('15')
|
||||
fee.linked_currency = Mock(factor=Decimal('0.01'))
|
||||
fee.linked_unit = Mock()
|
||||
fee.unit = Mock()
|
||||
Uom = Mock()
|
||||
Uom.compute_qty.return_value = Decimal('2')
|
||||
|
||||
with patch('trytond.modules.purchase_trade.fee.Pool') as PoolMock:
|
||||
PoolMock.return_value.get.return_value = Uom
|
||||
|
||||
fee.on_change_linked_price()
|
||||
|
||||
self.assertEqual(fee.price, Decimal('0.3000'))
|
||||
|
||||
def test_fee_pnl_regeneration_uses_shipment_lotqt_purchase_line(self):
|
||||
'fee pnl regeneration follows shipment lot.qt back to purchase line'
|
||||
Fee = Pool().get('fee.fee')
|
||||
|
||||
@@ -3,6 +3,20 @@
|
||||
<field name="type"/>
|
||||
<label name="product"/>
|
||||
<field name="product"/>
|
||||
<label name="currency"/>
|
||||
<field name="currency"/>
|
||||
<label name="mode"/>
|
||||
<field name="mode"/>
|
||||
<label name="price"/>
|
||||
<field name="price"/>
|
||||
<label name="enable_linked_currency"/>
|
||||
<field name="enable_linked_currency"/>
|
||||
<label name="linked_currency"/>
|
||||
<field name="linked_currency"/>
|
||||
<label name="linked_unit"/>
|
||||
<field name="linked_unit"/>
|
||||
<label name="linked_price"/>
|
||||
<field name="linked_price"/>
|
||||
<!-- <label name="supplier"/>
|
||||
<field name="supplier"/>
|
||||
<label name="p_r"/>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<field name="lot_pur_inv_state"/>
|
||||
<field name="lot_sale_inv_state"/>
|
||||
<field name="lot_quantity"/>
|
||||
<field name="sale_invoice_padding"/>
|
||||
<field name="lot_diff_quantity"/>
|
||||
<field name="lot_unit"/>
|
||||
<field name="lot_price"/>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<field name="lot_qt"/>
|
||||
<field name="lot_quantity"/>
|
||||
<field name="lot_gross_quantity"/>
|
||||
<field name="sale_invoice_padding"/>
|
||||
<field name="lot_quantity_new"/>
|
||||
<field name="lot_gross_quantity_new"/>
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user