Hi, I am using Odoo v11.0 CE on Win10
I inherits from stock move and add some fields
every thing on client form is perfect
but when click on save button all values resets to 0.
Here is My Code
Thanks in advance
from odoo import models,fields, api
from odoo.addons import decimal_precision as dp
from num2words import num2words
class StockMove(models.Model):
_inherit = "stock.move"
currency_id = fields.Many2one(related='picking_id.currency_id',
store=True,
string='Currency',
readonly=True
)
price_unit_br = fields.Float(string='U. Price',
required=True,
digits=dp.get_precision('Product Price'),
compute='_compute_price_unit',
store=True
)
price_total_br = fields.Float(string='Total',
digits=dp.get_precision('Product Price'),
store=True,
compute='_compute_price_total'
)
qty_stock_location_br = fields.Float(string='Av. Qty')
@api.one
@api.depends('price_unit_br', 'qty_stock_location_br')
def _compute_price_total(self):
for line in self:
line.price_total_br = line.price_unit_br * line.qty_stock_location_br
@api.onchange('product_id', 'location_id')
def _onchange_stock_qty(self):
stock_domain = [
('product_id', '=', self.product_id.id),
('location_id', '=', self.location_id.id),
]
stock_av_qty = self.env['stock.quant'].\
search(stock_domain, limit=1).quantity
if stock_av_qty:
self.qty_stock_location_br = stock_av_qty
else:
self.qty_stock_location_br = 1000
@api.depends("product_id", "product_uom")
def _compute_price_unit(self):
for line in self:
po_domain = [
('product_id', '=', line.product_id.id),
('product_uom', '=', line.product_uom.id)
]
price_unit = self.env['purchase.order.line'].\
search(po_domain, order='date_planned', limit=1).price_unit
if price_unit > 0:
line.price_unit_br = price_unit
else:
line.price_unit_br = line.product_id.standard_price