update Product Sales Price (list_price) from Sale Order (SO) unit price

There are 2 options to implement this solution. 

One is building everything from scratch. It means you are required to make a module for this. Of course it will take some time and you need to be familiar with python code. Actually, the code for this solution is not very long. 

Another one is you follow my below instruction and no need to write module and only some few lines of python code. It takes less than 5 minutes.

First, download and install the following module. It is completely free. 

https://apps.odoo.com/apps/modules/13.0/hcs_sale_price_history/

Second, enable the debug mode and go to Server Actions. You need to choose Product Template model and you can create another one for Product Product model. In the "Action to Do", select "Execute Python Code", put the below codes. Click "Create Contextual Action" and you will see this action in the "Action" menu.

for rec in records:
temp = rec['list_price']
if rec.attribute_sales_ids is not None:
for x in rec.attribute_sales_ids:
if x.currency_id != rec['company_id'].currency_id:
if x.currency_id.rate is not None and x.currency_id.rate > 0:
temp = x.price_unit / x.currency_id.rate
else:
temp = x.price_unit
 
if rec['list_price'] != temp:
rec['list_price'] = round(temp, 5)
break

 

For the Schedule Action, simply put the following line of code in the line 1, before "for rec in records"

records = env['product.template'].search([])

 

hcs_sale_price_history edit for other version like odoo 12. Otherwise, it will cause an error [AttributeError: 'bool' object has no attribute 'Ref']

Replace some codes in the models.py 

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

so_order_date = fields.Datetime('Order_Date', related='order_id.date_order', store=False, readonly=True)
product_tmpl_id = fields.Many2one('product.template', string='Product Tmpl Id', related='product_id.product_tmpl_id', readonly=True)
 
# product_tmpl_id = fields.Many2one('product.template', compute='_compute_parent_values')
# partner_id = fields.Many2one('res.partner', compute='_compute_parent_values')
# user_id = fields.Many2one('res.users', compute='_compute_parent_values')
# date_order = fields.Datetime(compute='_compute_parent_values')

# @api.depends('partner_id')
# def _compute_parent_values(self):
# for record in self:
# record.partner_id = record.order_id.partner_id.id
# record.product_tmpl_id = record.product_id.product_tmpl_id.id
# record.user_id = record.order_id.user_id.id
# record.date_order = record.order_id.date_order

 

views.xml

<field name="order_partner_id" optional="show"/>
<!-- <field name="partner_id" string="Customer" optional="show"/> -->
<!-- <field name="user_id" string="Sales Person" optional="show"/> -->
<field name="order_id" optional="show"/>
<field name="so_order_date" string="Order Date" optional="show"/>
<!-- <field name="product_tmpl_id" string="Product" optional="show"/> -->
<field name="product_uom_qty" optional="show"/>
<field name="price_unit" optional="show"/>
<field name="price_subtotal" optional="show"/>