Hello,
i porting/developing a module (working un V8).
It have a wizard , from the wizard we jump to a editable tree view with results and the option to confirm the operation.
I create the model (transient) en when clicking in the button (confirm the action) the data in the form get lost, all the fields cames empty
Here is my code:
the XML:
product.prices_update_wizard_result
product.prices_update_wizard_result
product.prices_update_wizard_result_detail.tree
product.prices_update_wizard_result_detail
and the py file:
class prices_update_wizard_result_detail(models.TransientModel):
_name = 'product.prices_update_wizard_result_detail'
_description = "details results"
result_id = fields.Many2one(
'product.prices_update_wizard_result', 'Result')
product_tmpl_id = fields.Many2one(
'product.template', 'Product Template',
readonly=True)
old_price = fields.Float(
'Old Price',
readonly=True)
new_price = fields.Float(
'New Price',
required=True
)
class prices_update_wizard_result(models.TransientModel):
_name = 'product.prices_update_wizard_result'
_description = "results"
@api.model
def default_get(self, fields_list):
res=super(prices_update_wizard_result,self).default_get(fields_list)
ret = []
price_discount = self._context.get('price_discount', 0.0)
price_surcharge = self._context.get('price_surcharge', 0.0)
price_round = self._context.get('price_round', 0.0)
product_tmpl_ids = self._context.get('product_tmpl_ids', [])
price_type = self._context.get('price_type', False)
for product_tmpl in self.env['product.template'].browse(
product_tmpl_ids):
if price_type == 'list_price':
old_price = product_tmpl.list_price
elif price_type == 'standard_price':
old_price = product_tmpl.standard_price
else:
raise UserError(_('Price type "%s" is not implemented') % (price_type))
vals = {
'product_tmpl_id': product_tmpl.id,
'old_price': old_price,
'new_price': self.env[
'product.prices_update_wizard'].calc_new_price(
old_price, price_discount,
price_surcharge, price_round),
}
ret.append([0,0,vals])
res.update({'detail_ids':ret})
return res
detail_ids = fields.One2many(
'product.prices_update_wizard_result_detail',
'result_id',
string='Products Detail',
store=False,
)
def confirm(self):
products_vals = []
price_type = self._context.get('price_type', False)
for line in self.detail_ids: #self.detail_ids comes empty
vals = {
'product_tmpl': line.product_tmpl_id,
'new_price': line.new_price,
}
products_vals.append(vals)
return self.env['product.prices_update_wizard'].update_prices(
products_vals, price_type)
if i change to models.Model works, but, if i perform a inline editiong, don't get stored in the self.detail_ids
Try with force_save but not solved at all
Any idea of any posible solution?
cant post xml code
here it goes
<record id="view_prices_update_wizard_result_form" model="ir.ui.view">
<field name="name">product.prices_update_wizard_result</field>
<field name="model">product.prices_update_wizard_result</field>
<field name="arch" type="xml">
<form string="Products">
<header>
<button name="confirm" string="Confirm" type="object" class="oe_highlight" />
</header>
<field name="detail_ids" force_save = "1"/>
</form>
</field>
</record>
<record id="view_prices_update_wizard_result_detail_tree" model="ir.ui.view">
<field name="name">product.prices_update_wizard_result_detail.tree</field>
<field name="model">product.prices_update_wizard_result_detail</field>
<field name="arch" type="xml">
<tree string="Products" create="false" editable="top">
<field name="product_tmpl_id" force_save = "1"/>
<field name="old_price" force_save = "1"/>
<field name="new_price" force_save = "1"/>
</tree>
</field>
</record>