class StockPicking(models.Model): _inherit = ['stock. Picking'] _description = 'test.test' _order = 'id'
def _default_group_id(self): if self.env.context.get('default_picking_id'): return self.env['stock. Picking'].browse(self.env.context['default_picking_id']).group_id.id return False
1.Inventory--->tranfers--->create----> quantity_done(Done) value fetch employee_id = fields.Many2one('hr.employee', 'Employee') product_id = fields.Many2one('product. Product', string='Product', check_company=True) department_id = fields.Many2one('hr. Department', string='Department') product_id = fields.Many2one('product.product', string='Product', check_company=True)
employee = fields. Char('hr.employee', related='employee_id.name')
department = fields. Char('hr. Department', related='department_id.name')
products = fields.Char('product.product', related='product_id.name')
product_uom = fields.Many2one('uom.uom', "UoM", required=True,
domain="[('category_id', '=', product_uom_category_id)]")
quantity_done = fields. Float('Quantity Done', compute='_quantity_done_compute', digits='Product Unit of Measure',
inverse='_quantity_done_set')
def change_release_date(self):
# stock_move = self.env['stock. Move'].search([('product_id', '=', self._ids)])
new = 'Employee Name:-' + str(self. Employee)
new1 = 'Department:-' + str(self. Department)
new2 = ' Date:-' + self.scheduled_date.strftime(
'%Y-%m-%d,%H:%M:%S %p')
new3 = 'Asset Name:-' + str(self. Products)
new4 = 'Reference No:-' + self.name
new5 = 'Quantity:-' + str(self.quantity_done)
new_data = " " + new + "\n " + new1 + "\n" + new2 + "\n " + new3 + "\n " + new4 + "\n" + " " + new5
img = qrcode.make(new_data)
print(new_data)
img.save('C:/odoo/custom_addons/qr/qr1.png')
def _quantity_done_compute(self):
if not any(self._ids):
# onchange
for move in self:
quantity_done = 0
for move_line in move._get_move_lines():
quantity_done += move_line.product_uom_id._compute_quantity(
move_line.qty_done, move.product_uom, round=False)
move.quantity_done = quantity_done
else:
# compute
move_lines_ids = set()
for move in self:
move_lines_ids |= set(move._get_move_lines().ids)
data = self.env['stock.move.line'].read_group(
[('id', 'in', list(move_lines_ids))],
['move_id', 'product_uom_id', 'qty_done'], ['move_id', 'product_uom_id'],
lazy=False
)
rec = defaultdict(list)
for d in data:
rec[d['move_id'][0]] += [(d['product_uom_id'][0], d['qty_done'])]
for move in self:
uom = move.product_uom
move.quantity_done = sum(
self.env['uom.uom'].browse(line_uom_id)._compute_quantity(qty, uom, round=False)
for line_uom_id, qty in rec.get(move.ids[0] if move.ids else move.id, [])
)
def _get_move_lines(self):
self.ensure_one()
if self.picking_type_id.show_reserved is False:
return self.move_line_nosuggest_ids
return self.move_line_ids