# -*- coding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in module root
# directory
##############################################################################
from openerp import models, fields, api, _
from openerp.exceptions import Warning
import logging
_logger = logging.getLogger(__name__)


class product_product(models.Model):
    _inherit = "product.product"

    # lst_price now cames from computed_list_price
    lst_price = fields.Float(
        compute='_product_lst_price',
        inverse='_set_product_lst_price',
        )

    @api.multi
    def _product_lst_price(self):
        for product in self:
            if 'uom' in self._context:
                uom = product.uos_id or product.uom_id
                lst_price = self.env['product.uom']._compute_price(
                    uom.id, product.computed_list_price, self._context['uom'])
            else:
                lst_price = product.computed_list_price
            product.lst_price = lst_price + product.price_extra

    @api.multi
    def _set_product_lst_price(self):
        for product in self:
            lst_price = product.lst_price
            if 'uom' in self._context:
                uom = product.uos_id or product.uom_id
                lst_price = self.env['product.uom']._compute_price(
                    self._context['uom'], lst_price, uom.id)
            product.computed_list_price = lst_price - product.price_extra


class product_template(models.Model):
    _inherit = "product.template"

    # lst_price now cames from computed_list_price
    lst_price = fields.Float(
        related='computed_list_price',
        )
    computed_list_price = fields.Float(
        string='Sale Price',
        compute='_get_computed_list_price',
        inverse='_set_prices',
        help='Computed Sale Price. This value depends on "Sale Price Type" an '
        'other parameters. If you set this value, other fields will be '
        'computed automatically.',
        )
    list_price_type = fields.Selection([
        ('manual', 'Manual')],
        string='Sale Price Type',
        required=True,
        default='manual',
        )
    computed_list_price_currency_id = fields.Many2one(
        'res.currency',
        string='Computed List Price Currency',
        compute='get_computed_list_price_currency',
        )

    @api.model
    def _get_price_type(self, price_type):
        price_type = self.env['product.price.type'].search(
            [('field', '=', price_type)], limit=1)
        if not price_type:
            raise Warning(_('No Price type defined for field %s' % (
                price_type)))
        return price_type

    @api.multi
    def get_computed_list_price_currency(self):
        price_type = self._get_price_type('computed_list_price')
        for product in self:
            product.computed_list_price_currency_id = price_type.currency_id

    @api.multi
    @api.depends(
        'list_price_type',
        'list_price',
        )
    def _get_computed_list_price(self):
        for template in self:
            computed_list_price = template.get_computed_list_price()
            _logger.info('Compute Lis Price calculated = "%s"' % (
                computed_list_price))
            template.computed_list_price = computed_list_price

    @api.multi
    def _set_prices(self):
        _logger.info('Set Prices from "computed_list_price"')
        for template in self:
            template.set_prices()

    @api.multi
    def set_prices(self):
        self.ensure_one()
        if self.list_price_type == 'manual':
            _logger.info('Set Prices from "computed_list_price" type "manual"')
            self.list_price = self.computed_list_price

    @api.multi
    def get_computed_list_price(self):
        _logger.info('Get computed_list_price')
        self.ensure_one()
        return self.list_price

    @api.model
    def _price_get(self, products, ptype='list_price'):
        """
        For price type "computed_list_price" we also add variants price_extra
        """
        res = super(product_template, self)._price_get(products, ptype)
        if ptype == 'computed_list_price':
            for product in products:
                res[product.id] += (
                    product._name == "product.product" and
                    product.price_extra or 0.0)
        return res

@@ -570,16 +570,29 @@
 mpute='_
+computed_get_
 product_
@@ -617,24 +617,33 @@
   inverse='_
+computed_
 set_product_
@@ -688,16 +688,29 @@
     def 
+_computed_get
 _product
@@ -1155,24 +1155,33 @@
 lti%0A    def 
+_computed
 _set_product

FIX computed list price