Odoo Help

0

0
1 Answer
1
Avatar

Maniganda India

--Maniganda--

1225
| 6 8 9
Bangalore, India
--Maniganda--
Maniganda India
00:41, 06/09/2019

Hello,

You can try tis


class RawMaterialReport(models.Model):
_name = 'raw.material.report'
_description = 'Raw Material Report'

product_id = fields.Many2one('product.product', string='Product', required=False)
code = fields.Char(string='Code', required=True, readonly=True)
total_qty = fields.Float(string='Total Qty', digits=(6, 2), readonly=True)
virtual_qty = fields.Float(string='Forcasted Qty', digits=(6, 2), readonly=True)
origin = fields.Char(string='Origin', required=True, readonly=True)
production_id = fields.Many2one('mrp.production')


@api.multi
def open_raw_materials(self):
data = {}
self.search([]).unlink()
mrp_productions = self._context.get('active_ids')
mrp_production = self.env['mrp.production'].browse(mrp_productions)
products_without_default_code = mrp_production.mapped('move_raw_ids').filtered(
lambda x: not x.product_id.default_code
)

raws = mrp_production.mapped('move_raw_ids').sorted(
key=lambda r: r.product_id.default_code
)

for r in raws:
key = (r.product_id.id, r.raw_material_production_id.id)
if key not in data:
data[key] = {
'product_id': r.product_id.id,
'code': r.product_id.default_code,
'total_qty': r.product_id.qty_available,
'virtual_qty': r.product_id.virtual_available,
'origin': r.reference,
'production_id': r.raw_material_production_id.id,
}
else:
data[key].update({
'total_qty' : data[key].get('total_qty') + r.product_id.qty_available,
})
for vals in data:
self.create(data[vals])
Ask a Question
Writer
Tags
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now