تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
6950 أدوات العرض

i added 'product_dimension' field in 'sale.order.line' and want to send it's value to 'stock.move' so i did :

class InheritStockMove(models.Model):
_inherit = 'stock.move'

product_dimension = fields.Char()

then :

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

product_dimension = fields.Char(string="Dimension")

def _prepare_procurement_values(self, group_id=False):
res = super(InheritSaleOrderLine, self)._prepare_procurement_values(group_id)
res.update({'product_dimension': self.product_dimension})
return res


then i added :

class StockRuleInherit(models.Model):
_inherit = 'stock.rule'

def _get_stock_move_values(self, product_id, product_qty, product_uom, location_id, name, origin, values, group_id):
res = super(StockRuleInherit, self)._get_stock_move_values(product_id, product_qty, product_uom, location_id,
name, origin, values, group_id)
res['product_dimension'] = values.get('product_dimension', False)
return res

but i get this error :
res['product_dimension'] = values.get('product_dimension', False) AttributeError: 'res.company' object has no attribute 'get'
الصورة الرمزية
إهمال
أفضل إجابة

you can try this way:
class InheritSaleOrderLine(models.Model):

_inherit = 'sale.order.line'


product_dimension = fields.Char(string="Dimension")


def _prepare_procurement_values(self, group_id=False):

res = super(InheritSaleOrderLine, self)._prepare_procurement_values(group_id)

res.update({'product_dimension': self.product_dimension})

return res


class StockRuleInherit(models.Model):

_inherit = 'stock.rule'


def _get_stock_move_values(self, product_id, product_qty, product_uom, location_id, name, origin, values, group_id):

res = super(StockRuleInherit, self)._get_stock_move_values(product_id, product_qty, product_uom, location_id,

name, origin, values, group_id)

res['product_dimension'] = values.get('product_dimension', False)

return res



make sure that the values parameter passed to the _get_stock_move_values method is a dictionary containing the required information. Additionally, ensure that you are passing the correct arguments when calling the _prepare_procurement_values method to set the product_dimension field value.

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

You cannot use the get method on values because it is an instance of the res.company object and not a dictionary, which is why you are getting the problem. Field values from the stock.move records are contained in the values parameter. You must use dot notation to directly retrieve the value of the product_dimension field from the values object.

Inherit sale.order.line and override the _prepare_procurement_values method to include the product_dimension:

from odoo import models, fields

class InheritSaleOrderLine(models.Model):
    _inherit =
'sale.order.line'
  
    product_dimension = fields.Char(string=
"Dimension")
  
   
def _prepare_procurement_values(self, group_id=False):
        res =
super(InheritSaleOrderLine, self)._prepare_procurement_values(group_id)
        res.update({
           
'product_dimension': self.product_dimension,
        })
       
return res

Hope it helps

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
أغسطس 20
6523
4
مايو 24
12633
1
أبريل 24
3271
0
نوفمبر 23
2020
1
سبتمبر 23
2104