65 lines
2.8 KiB
Python
65 lines
2.8 KiB
Python
from odoo import fields, models, api, _
|
|
from odoo.exceptions import UserError
|
|
|
|
class stockPicking(models.Model):
|
|
_inherit = 'stock.picking'
|
|
|
|
vehicle_no = fields.Char(string="Vehicle No")
|
|
distance = fields.Float(string="Distance (km)")
|
|
landed_cost_ids = fields.Many2many('stock.landed.cost', compute="_compute_landed_cost_ids")
|
|
contains_raw_material = fields.Boolean(compute="_compute_check_raw_material", store=True)
|
|
|
|
@api.depends("move_ids_without_package.product_id.categ_id")
|
|
def _compute_check_raw_material(self):
|
|
raw_category = self.env.ref("aui_custom_module.category_raw_material")
|
|
|
|
for picking in self:
|
|
picking.contains_raw_material = any(
|
|
move.product_id.categ_id == raw_category
|
|
for move in picking.move_ids_without_package
|
|
if move.product_id
|
|
)
|
|
|
|
# def _set_lot_producing(self):
|
|
# self.ensure_one()
|
|
# for move_id in self.move_ids:
|
|
# self.ensure_one()
|
|
# name = self.env['ir.sequence'].next_by_code('stock.lot.serial')
|
|
# exist_lot = not name or self.env['stock.lot'].search([
|
|
# ('product_id', '=', move_id.product_id.id),
|
|
# '|', ('company_id', '=', False), ('company_id', '=', self.company_id.id),
|
|
# ('name', '=', name),
|
|
# ], limit=1)
|
|
# if exist_lot:
|
|
# name = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id)
|
|
# if not name:
|
|
# raise UserError(_("Please set the first Serial Number or a default sequence"))
|
|
# for line in self.move_line_ids:
|
|
# line.lot_name = self._prepare_stock_lot_values()
|
|
|
|
@api.depends('state')
|
|
def _compute_landed_cost_ids(self):
|
|
for rec in self:
|
|
if rec.state == 'done':
|
|
rec.landed_cost_ids = self.env['stock.landed.cost'].sudo().search([('picking_ids','in',[rec.id])]).ids
|
|
else:
|
|
rec.landed_cost_ids = False
|
|
|
|
def action_open_landing_cost(self):
|
|
for rec in self:
|
|
if rec.state == 'done':
|
|
return {
|
|
'name': _('Landing Cost'),
|
|
'view_mode': 'form',
|
|
'view_id': self.env.ref('aui_custom_module.view_stock_landed_cost_form_2').id,
|
|
'res_model': 'stock.landed.cost',
|
|
'type': 'ir.actions.act_window',
|
|
'context': {
|
|
'default_picking_ids': [(6, 0, rec.filtered(lambda picking: picking.move_ids.stock_valuation_layer_ids != False and picking.state == 'done' and picking.company_id == self.env.company).ids)],
|
|
'picking_domain_ids': [self.id],
|
|
},
|
|
'target': 'new',
|
|
}
|
|
|
|
|