跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

M

mrchengjin

@mrchengjin
关于
帖子
4
主题
1
群组
0
粉丝
0
关注
0

帖子

最新 最佳 有争议的

  • 添加新的total quantity
    M mrchengjin

    sale.py
    # -- coding: utf-8 --

    from osv import osv,fields
     
    class sale_order(osv.osv):
    _name='sale.order'
    _inherit = 'sale.order'

    def qty_all(self, cr, uid, ids, field_name, arg, context=None):
    res = {}
    for order in self.browse(cr, uid, ids, context=context):
    res[order.id] = {
    'total_quantity': 0.0,
    }
    val2 = 0.0
    for line in order.order_line:
    val2 += line.product_uom_qty
    res[order.id] = val2
    return res

    def _get_order(self, cr, uid, ids, context=None):
    result = {}
    for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
    result[line.order_id.id] = True
    return result.keys()

    _columns = {

    'total_quantity':fields.function(qty_all,type='float',string='Total Quantity',
    store={
    'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
    'sale.order.line': (_get_order, ['product_uom_qty'], 10),
    }, help="The total quantity", track_visibility='always'),
    }

    经修改和测试后能用的代码,谢谢大家指导.
    6.1测试成功,如果已经建立的表单,需要修改表单里的产品数量(任意)并保存才能显示新的计算产品量


  • 添加新的total quantity
    M mrchengjin

    回的值还是不对,还是0.00,请指点


  • 添加新的total quantity
    M mrchengjin

    添加return res[order.id]=value? 还是别的,请解释下,不太明白,谢谢


  • 添加新的total quantity
    M mrchengjin

    sale.py
    from osv import osv,fields
     
    class sale_order(osv.osv):
    _name='sale.order'
    _inherit = 'sale.order'

    def amount_all(self, cr, uid, ids, field_name, arg, context=None):
    res = {}
    for order in self.browse(cr, uid, ids, context=context):
    res[order.id] = {
    'total_quantity': 0.0,
    }
    val2 = 0.0
    for line in order.order_line:
    val2 += line.product_uom_qty
    res[order.id]['total_quantity'] = val2
    return res

    def _get_order(self, cr, uid, ids, context=None):
    result = {}
    for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
    result[line.order_id.id] = True
    return result.keys()

    _columns = {
     
    'total_quantity':fields.function(amount_all,type='float',string='Total Quantity',
    store={
    'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
    'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
    },
    multi='sums', help="The total quantity", track_visibility='always'),
    }
           
    sale_order() 

    sale_view.xml
    <xpath expr="//field[@name='amount_untaxed']" position="before">
    <field name="total_quantity" />
    </xpath>

    新添加的total_quantity field 回值显示0.00. 无报错,问题出在那里,请有经验的解答下, 求的值是全订单的物品数量值.谢谢

  • 登录

  • 没有帐号? 注册

  • 登录或注册以进行搜索。
  • 第一个帖子
    最后一个帖子
0
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组