py源码:
from odoo.report import report_sxw
from odoo import models
from odoo import models, api, fields, _
class stock_picking_report(models.AbstractModel):
_name = 'report.stock_report.stock_picking_report'
@api.model
def render_html(self, docids, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('stock_report.stock_picking_report')
spk = self.env['stock.picking'].search([('id','=',docids)])
docargs = {
'doc_ids': docids,
'doc_model': report.model,
'docs': self,
'spk': spk,
'get_all': self.get_all,
'print_data': self.print_data,
'get_qty_done_sum': self.get_qty_done_sum,
}
return report_obj.render('stock_report.stock_picking_report', docargs)
def get_all(self, para):
self._cr.execute("""\
SELECT pp.id as product_id,pt.id as tmpl_id,pu.name as uom_name,spol.lot_uom_ratio,
spol.lot_uom_qty,spol.qty,t.often_uom,concat(spl.ref,'-',spl.name) as lot,sl.name origin_name,
loc.loc_id dest_location FROM stock_picking sp
LEFT JOIN stock_pack_operation spo ON spo.picking_id=sp.id
LEFT JOIN stock_pack_operation_lot spol ON spol.operation_id=spo.id
LEFT JOIN product_uom pu ON pu.id = spol.lot_uom
LEFT JOIN stock_production_lot spl on spl.id = spol.lot_id
LEFT JOIN product_product pp on pp.id=spo.product_id
LEFT JOIN product_template pt ON pt.id = pp.product_tmpl_id
LEFT JOIN stock_location sl on sl.id = spo.location_id
LEFT JOIN
(select sl.id as loc_id,sl.name,spol.id FROM stock_picking sp
LEFT JOIN stock_pack_operation spo ON spo.picking_id=sp.id
LEFT JOIN stock_pack_operation_lot spol ON spol.operation_id=spo.id
LEFT JOIN stock_location sl on sl.id = spo.location_dest_id
where sp.id =%s) loc on loc.id=spol.id
LEFT JOIN
(SELECT pu.name AS often_uom,pp.id FROM product_product pp
LEFT JOIN product_template pt ON pt.id = pp.product_tmpl_id
LEFT JOIN product_uom pu ON pu.id=pt.uom_id)t ON t.id=spo.product_id
where sp.id =%s order by pt.id
""" % (para,para))
return self._cr.dictfetchall()
def print_data(self,para):
dict = {}
list = []
flagA='1'
flagB='1'
sum=0
i=0
for pd in self.get_all(para):
i=i+1
flagA = pd['tmpl_id']
if flagA != flagB:
if flagB != '1':
dict['line'] = ''
dict['product_id'] = '小计'
dict['tmpl_id'] = ''
dict['uom_name'] = ''
dict['lot_uom_ratio'] = ''
dict['lot_uom_qty'] = ''
dict['often_uom'] = ''
dict['lot'] = ''
dict['origin_name'] = ''
dict['dest_location'] = ''
dict['qty'] = sum
list.append(dict.copy())
sum = 0
flagB = flagA
sum = sum + pd['qty']
dict['line'] = i
prd = self.env['product.product'].search([('id', '=', pd['product_id'])])
dict['product_id'] = prd.display_name
dict['tmpl_id'] = pd['tmpl_id']
dict['uom_name'] = pd['uom_name']
dict['lot_uom_ratio'] = pd['lot_uom_ratio']
dict['lot_uom_qty'] = pd['lot_uom_qty']
dict['qty'] = pd['qty']
dict['often_uom'] = pd['often_uom']
dict['lot'] = pd['lot']
dict['origin_name'] = pd['origin_name']
sl = self.env['stock.location'].search([('id', '=', pd['dest_location'])])
dict['dest_location'] = sl.display_name
list.append(dict.copy())
dict['product_id'] = '小计'
dict['line'] = ''
dict['tmpl_id'] = ''
dict['uom_name'] = ''
dict['lot_uom_ratio'] = ''
dict['lot_uom_qty'] = ''
dict['often_uom'] = ''
dict['lot'] = ''
dict['origin_name'] = ''
dict['dest_location'] = ''
dict['qty'] = sum
list.append(dict.copy())
return list
def get_qty_done_sum(self, para):
self._cr.execute("""\
select sum(qty_done) from stock_picking sp
left join stock_pack_operation spo on sp.id=spo.picking_id where sp.name=\'%s\'
""" % para)
return self._cr.fetchall()
代码上方注释部分为原生odoo pdf开发文件,下方的def render_html(XXX)为自定义模型.
return self._cr.dictfetchall() #返回字典型结果集
return self._cr.fetchall() #返回列表型结果集
Xml文件:
单
合作伙伴:
开单单位:
单据号:
单据日期:
行号
产品名称
辅助单位
换算率
辅助单位数量
数量
主计量单位
批次/序列号
来源位置
目的位置
备注
合计
备注:
核决:
审核:
经办:
请打印已完成单据