Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
4622 Widoki

Our client has dynamic market pricing which changes on a weekly basis. We have two price lists: Retail and Wholesale.

When I import the updated price lists into the product.template via .csv file, it creates a duplicate entry instead of overriding the value. Is there a way to override a Price List price?

We started investigated other means of doing this and came across an app that updates the Sale Price and Cost Price, can any one give me suggestions on how I could apply this to our price lists?

class ProductPrice(models.TransientModel):

_name = 'product.price'

name = fields.Many2one('product.template', string="Product", required=True)
sale_price = fields.Integer(string="Sale Price", required=True)
cost_price = fields.Integer(string="Cost Price", required=True)
retail_price = fields.Integer(string="Retail Price", required=True)

def change_product_price(self):
prod_obj = self.env['product.template'].search([('id', '=', self.name.id)])
prod_value = {'list_price': self.sale_price, 'standard_price': self.cost_price, 'product_pricelist.id.fixed_price': self.retail_price}
prod_obj.write(prod_value)
return {
'name': _('Products'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'product.template',
'type': 'ir.actions.act_window',
'res_id': prod_obj.id,
'context': self.env.context
}

@api.onchange('name')
def get_price(self):
self.sale_price = self.name.list_price
self.cost_price = self.name.standard_price
self.retail_price = self.name.product_pricelist.id.fixed_price
Awatar
Odrzuć
Autor Najlepsza odpowiedź

Hope this may be helpful to the community, here's how we solved it:

from odoo import models, fields, api, _
from odoo.addons import decimal_precision as dp
import logging

_logger = logging.getLogger(__name__) class ProductPrice(models.TransientModel): _name = 'product.price' name = fields.Many2one(
'product.template',
string="Product",
required=True,
)
sale_price = fields.Float( string="Sale Price", digits=dp.get_precision('Product Price'), required=True, ) does_retail_exist = fields.Boolean( string="Is there a retail price for this product", default=False, ) retail_price = fields.Float( string="Retail Price", digits=dp.get_precision('Product Price'), required=True,
) does_wholesale_exist = fields.Boolean( string="Is there a wholesale price for this product", default=False,
) wholesale_price = fields.Float( string="Wholesale Price", digits=dp.get_precision('Product Price'), required=True, )
def change_product_price(self): _logger.info('[CHANGE PRICE]') prod_obj = self.env['product.template'].search([('id', '=', self.name.id)]) # Set list price if self.does_retail_exist == False: prod_value = {'list_price': self.sale_price} prod_obj.write(prod_value) else: prod_value = {'list_price': self.retail_price} prod_obj.write(prod_value)
# Set retail and wholesale price if they exist for child in prod_obj.item_ids: _logger.info('[CHANGE PRICE] - Name: %s Value: %f', child.pricelist_id.name, child.fixed_price) if child.pricelist_id.name == 'Retail Price': 
child.write({'fixed_price': self.retail_price}) elif child.pricelist_id.name == 'Wholesale Price': 
child.write({'fixed_price': self.wholesale_price}) return { 'name': _('Products'), 'view_type': 'form', 'view_mode': 'form', 'res_model': 'product.template', 'type': 'ir.actions.act_window', 'res_id': prod_obj.id, 'context': self.env.context } @api.onchange('name') def get_price(self): _logger.info('[GET PRICE]') self.does_retail_exist = False self.does_wholesale_exist = False self.sale_price = self.name.list_price for child in self.name.item_ids: _logger.info('[PRODUCT PRICE] - Name: %s Value: %f', child.pricelist_id.name, child.fixed_price) if child.pricelist_id.name == 'Retail Price': 
self.does_retail_exist = True self.retail_price = child.fixed_price elif child.pricelist_id.name == 'Wholesale Price': 
self.does_wholesale_exist = True self.wholesale_price = child.fixed_price
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
gru 20
2116
0
lis 20
2104
1
lis 19
7884
1
cze 25
629
2
kwi 25
1028