This is my code
class Picking(models.Model):
_inherit = "stock.picking"
issued_material = fields.One2many('bi.issue.material','issue_line')
@api.multi
def issue_material(self):
jobsheet_no = self.jobsheet_no
self.ensure_one()
result = []
self.env.cr.execute("""SELECT move.name as product,move.product_uom_qty as quantity,pick.name as delivered from stock_move move,stock_picking pick where move.picking_id = pick.id and move.state = 'done' and move.location_id!=9 and pick.jobsheet_no=%s"""%(jobsheet_no.id))
vals = self.env.cr.dictfetchall()
self.env['bi.issue.material'].search([]).unlink()
for order in vals:
job = {
'quantity': order['quantity'],
'product': order['product'],
'delivered': order['delivered']
}
result.append(job)
self.env.cr.execute("""SELECT move.name as product,move.product_uom_qty as quantity,pick.name as delivered from stock_move move,stock_picking pick where move.picking_id = pick.id and move.state = 'done' and move.location_id=9 and pick.jobsheet_no=%s"""%(jobsheet_no.id))
vals1 = self.env.cr.dictfetchall()
self.env['bi.issue.material'].search([]).unlink()
for order in vals1:
job1 = {
'quantity': order['quantity']*-1,
'product': order['product'],
'delivered': order['delivered']
}
result.append(job1)
if result:
per_url = {}
for entry in result:
key = entry['product']
if key not in per_url:
per_url[key] = entry.copy()
else:
per_url[key]['quantity'] += entry['quantity']
res=list(per_url)
for product in res:
if per_url[product]['quantity'] > 0.0:
self.env['bi.issue.material'].create(per_url[product])
class BiIssuedMaterial(models.Model):
_name = "bi.issue.material"
issue_line = fields.Many2one('stock.picking')
product = fields.Char("Products")
quantity = fields.Char("Quantity")
delivered = fields.Char("Delivered")
The xml code is
<xpath expr="//button[@name='do_new_transfer']" position="after">
<button name="issue_material" states="draft,confirmed,partially_available,assigned" string="Issued Material" groups="account.group_account_manager" type="object" class="oe_highlight" />
</xpath>
<xpath expr="//page[2]" position="after">
<page string="Issued Material">
<field name="issued_material">
<tree string="material Issued" editable="bottom" create="false">
<field name="product"/>
<field name="quantity"/>
<field name="delivered"/>
</tree>
</field>
</page>
</xpath>