On 2016-02-24 21:34, 'Hendrik Brandes' via tryton-dev wrote: > Hello, > > I have the following use case: We have a module called "sale_discount", > which enables discounting rules ( a table ) for different quantities of a > product.
This sounds like the price list. > First I have implemented a wizard like TestPaymentTerm, to display the > different values. Works nice. > Second, I want to display this as a separate page in the sale_line_form, so > the user can see each condition of the product. > > In SaleLine, I want to define the pricing_info as following: > > pricing_info = fields.One2Many('ebb.product.pricing.test.result', > None, 'Result', readonly=True) > > The method on_change_with_pricing_info returns the values and works also: > @fields.depends('product', 'unit', 'pricing_info') > def on_change_with_pricing_info(self): > ... > self.result = result > return self._changed_values.get('result', []) > > but when I execute this in the client on a sale I get the error > > ... > File "/trytond/model/fields/one2many.py", line 84, in get > field = Relation._fields[self.field] > KeyError: None > ... > > > I understand, that the One2Many needs a reference to the parent, but why > does this works in the TestPaymentTerm Dialog? Because wizard doesn't use ModelStorage but only ModelView and so it never tries to save or read it from the database. Maybe we could add a standard test to detect such case when the relation field are missing on ModelStorage class. > What will be a good way to implement such a feature in the sale_line? Does > it need, to create a ModelSQL? > Currently, the class "result" is implemented as ModelView with the needed > fields as readonly. Clearly, this is information that you compute so you must use a Function field. Or if the list can be based on a SQL query, you can define a ModelSQL as relation which is based on a 'table_query' [1] query. [1] http://doc.tryton.org/3.8/trytond/doc/ref/models/models.html?#trytond.model.ModelSQL.table_query -- Cédric Krier - B2CK SPRL Email/Jabber: cedric.kr...@b2ck.com Tel: +32 472 54 46 59 Website: http://www.b2ck.com/ -- You received this message because you are subscribed to the Google Groups "tryton-dev" group. To view this discussion on the web visit https://groups.google.com/d/msgid/tryton-dev/20160225092900.GS10143%40tetsuo.