如何使用 odoo 查询过滤、搜索、分组
how to filter,search,groupby with odoo query
在库存变动中我想按某些特定日期和分组 product_id、location_dest_id 和总和 product_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
I want to groupby all product_id and location_dest_id since i have plenty articles
然后将所有 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
在库存变动中我想按某些特定日期和分组 product_id、location_dest_id 和总和 product_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
I want to groupby all product_id and location_dest_id since i have plenty articles
然后将所有 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