From to + pricing component
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Bool, Eval, Id
|
||||
from trytond.pyson import Bool, Eval, Id, If
|
||||
from trytond.model import (ModelSQL, ModelView)
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.tools import is_full_text, lstrip_wildcard
|
||||
@@ -333,11 +333,11 @@ class Pricing(ModelSQL,ModelView):
|
||||
pricing_date = fields.Date("Date")
|
||||
price_component = fields.Many2One(
|
||||
'pricing.component', "Component",
|
||||
domain=[
|
||||
'OR',
|
||||
('line', '=', Eval('line', -1)),
|
||||
('sale_line', '=', Eval('sale_line', -1)),
|
||||
],
|
||||
domain=[If(Bool(Eval('line')),
|
||||
('line', '=', Eval('line')),
|
||||
If(Bool(Eval('sale_line')),
|
||||
('sale_line', '=', Eval('sale_line')),
|
||||
('id', '=', -1)))],
|
||||
depends=['line', 'sale_line'])#, ondelete='CASCADE')
|
||||
quantity = fields.Numeric("Qt",digits='unit')
|
||||
settl_price = fields.Numeric("Settl. price",digits='unit')
|
||||
|
||||
@@ -1101,6 +1101,19 @@ class Line(metaclass=PoolMeta):
|
||||
and bool(line.to_del)
|
||||
and line.from_del > line.to_del)
|
||||
|
||||
def _check_delivery_period(self):
|
||||
if self._has_invalid_delivery_period(self):
|
||||
raise UserError(
|
||||
"Delivery period From date must be before To date.")
|
||||
|
||||
@fields.depends('from_del', 'to_del')
|
||||
def on_change_from_del(self):
|
||||
self._check_delivery_period()
|
||||
|
||||
@fields.depends('from_del', 'to_del')
|
||||
def on_change_to_del(self):
|
||||
self._check_delivery_period()
|
||||
|
||||
quantity_theorical = fields.Numeric("Contractual Qt", digits='unit', readonly=False)
|
||||
price_type = fields.Selection([
|
||||
('cash', 'Cash Price'),
|
||||
|
||||
@@ -1084,6 +1084,19 @@ class SaleLine(metaclass=PoolMeta):
|
||||
and bool(line.to_del)
|
||||
and line.from_del > line.to_del)
|
||||
|
||||
def _check_delivery_period(self):
|
||||
if self._has_invalid_delivery_period(self):
|
||||
raise UserError(
|
||||
"Delivery period From date must be before To date.")
|
||||
|
||||
@fields.depends('from_del', 'to_del')
|
||||
def on_change_from_del(self):
|
||||
self._check_delivery_period()
|
||||
|
||||
@fields.depends('from_del', 'to_del')
|
||||
def on_change_to_del(self):
|
||||
self._check_delivery_period()
|
||||
|
||||
del_period = fields.Many2One('product.month',"Delivery Period")
|
||||
lots = fields.One2Many('lot.lot','sale_line',"Lots",readonly=True)
|
||||
fees = fields.One2Many('fee.fee', 'sale_line', 'Fees')
|
||||
|
||||
@@ -6,7 +6,7 @@ from decimal import Decimal
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval
|
||||
from trytond.pyson import Bool, Eval, If
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.modules.purchase_trade import valuation as valuation_module
|
||||
@@ -528,11 +528,11 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
'pricing component choices are limited to the purchase or sale line'
|
||||
Pricing = Pool().get('pricing.pricing')
|
||||
|
||||
self.assertEqual(Pricing.price_component.domain, [
|
||||
'OR',
|
||||
('line', '=', Eval('line', -1)),
|
||||
('sale_line', '=', Eval('sale_line', -1)),
|
||||
])
|
||||
self.assertEqual(Pricing.price_component.domain, [If(Bool(Eval('line')),
|
||||
('line', '=', Eval('line')),
|
||||
If(Bool(Eval('sale_line')),
|
||||
('sale_line', '=', Eval('sale_line')),
|
||||
('id', '=', -1)))])
|
||||
|
||||
def test_pricing_component_must_belong_to_pricing_owner(self):
|
||||
'pricing rows reject components from another purchase or sale line'
|
||||
@@ -579,6 +579,17 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
self.assertFalse(PurchaseLine._has_invalid_delivery_period(valid))
|
||||
self.assertFalse(SaleLine._has_invalid_delivery_period(valid))
|
||||
|
||||
purchase_line = PurchaseLine()
|
||||
purchase_line.from_del = invalid.from_del
|
||||
purchase_line.to_del = invalid.to_del
|
||||
sale_line = SaleLine()
|
||||
sale_line.from_del = invalid.from_del
|
||||
sale_line.to_del = invalid.to_del
|
||||
with self.assertRaises(UserError):
|
||||
purchase_line.on_change_from_del()
|
||||
with self.assertRaises(UserError):
|
||||
sale_line.on_change_to_del()
|
||||
|
||||
def test_pricing_eod_uses_weighted_average_for_manual_rows(self):
|
||||
'manual pricing eod uses the weighted average of fixed and unfixed legs'
|
||||
Pricing = Pool().get('pricing.pricing')
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<form>
|
||||
<field name="line" invisible="1"/>
|
||||
<field name="sale_line" invisible="1"/>
|
||||
<label name="pricing_date"/>
|
||||
<field name="pricing_date"/>
|
||||
<label name="price_component"/>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<tree>
|
||||
<field name="line" tree_invisible="1"/>
|
||||
<field name="sale_line" tree_invisible="1"/>
|
||||
<field name="pricing_date"/>
|
||||
<field name="price_component"/>
|
||||
<field name="quantity"/>
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
<tree>
|
||||
<field name="line" tree_invisible="1"/>
|
||||
<field name="sale_line" tree_invisible="1"/>
|
||||
<field name="pricing_date"/>
|
||||
<field name="price_component"/>
|
||||
<field name="quantity"/>
|
||||
|
||||
Reference in New Issue
Block a user