python - 如何使用 odoo 查询进行过滤、搜索、分组

标签 python odoo-10

在库存移动中,我想按某些特定日期和分组进行过滤:product_id、location_dest_id 和 sumproduct_uom_quantity。

@api.multi
    def compute_report(self):

       record_move= self.env['stock.move'].search([('date','>=',self.start_date)]).
        .read_group([('date','>=',self.start_date)],[sum('product_uom_quantity')],['product_id','location_dest_id'])
        return {'record_move': record_move}

最佳答案

domain = [('date', '=', specific_date),
          ('product_id', '=', id_of_the_product),
          ('location_dest_id', '=', id_of_location)]
record = self.env['stock.move'].search(domain)
sum=0
for rec in record:
   sum = sum + rec.product_uom_quantity
return sum

我想对所有的product_id和location_dest_id进行分组,因为我有很多文章

然后将所有product_id和location_dest_id读取到列表中

p = self.env['model_of_product'].search([])


_product=[]
# collect all product id
for product in p:
    _product.append(product.id)

box = []
for _p in _product:
    domain = [  ('date', '=', specific_date),
                ('product_id', '=', _p)]
    record = self.env['stock.move'].search(domain)
    sum_of_stock = 0
    sum_of_client = 0
    # box will contain sets of [product_id, sum_of_stock, sum_of_client ]
    for rec in record.search([('name', '=', 'Clients')]):
        sum_of_client = sum_of_client + rec.product_uom_quantity
    for rec in record.search([('name', '=', 'Stock')]):
        sum_of_stock = sum_of_stock + rec.product_uom_quantity

    box.append([_p, sum_of_stock, sum_of_client])
return box

关于python - 如何使用 odoo 查询进行过滤、搜索、分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56845782/

相关文章:

python - Flask-WTF : CSRF token missing

php - 在 hostgator 托管的 Web 服务器中安装 python 模块

python - 无法将特定文件复制到 Dockerfile 中的/app

python - 如何在 Odoo 中从产品模板属性行创建产品变体?

python - 如何使用 Selenium Python 定位元素

python - 语法错误 : keyword can't be an expression while creating a dictionary

javascript - 如何在 Odoo JavaScript 上检查某个表单 View 何时打开并且其中的字段已更改?

python - 如何将 sale.order.line 中的数据移动到交货订单 (stock.pack.operation)

python - Odoo 可以跟踪计算字段的变化