Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
AdriaGForgeFlow committed Oct 21, 2019
1 parent 6486484 commit 1a28667
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 86 deletions.
9 changes: 0 additions & 9 deletions stock_barcodes/wizard/stock_barcodes_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ class WizStockBarcodesRead(models.AbstractModel):
message = fields.Char(readonly=True)
manual_entry_message = fields.Char(readonly=True)

# @api.onchange('product_id')
# def onchange_product_id(self):
# if self.product_id:
# if not self.barcode or \
# (self.barcode and self.product_id.barcode != self.barcode):
# raise UserError(
# _('You need to be in Manual entry data mode to be able '
# 'to change the product. Please, remove entered product'))

@api.onchange('location_id')
def onchange_location_id(self):
self.packaging_id = False
Expand Down
89 changes: 26 additions & 63 deletions stock_barcodes/wizard/stock_barcodes_read_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class WizStockBarcodesReadPicking(models.TransientModel):
readonly=True,
)
scan_count = fields.Integer()
pack_operation_ids = fields.Many2many(
'stock.pack.operation', string="Operations",
readonly=True,
)

@api.depends('picking_id', 'scan_count')
def _compute_picking_quantity(self):
Expand Down Expand Up @@ -107,27 +111,15 @@ def onchange_product_id(self):
('id', 'in', candidate_picking_ids.ids)]}}
return

# def _set_default_picking(self):
# picking_id = self.env.context.get('default_picking_id', False)
# if picking_id:
# self._set_candidate_pickings(
# self.env['stock.picking'].browse(picking_id))

# @api.model
# def create(self, vals):
# # When user click any view button the wizard record is create and the
# # picking candidates have been lost, so we need set it.
# wiz = super(WizStockBarcodesReadPicking, self).create(vals)
# if wiz.picking_id:
# wiz._set_candidate_pickings(wiz.picking_id)
# return wiz

# @api.onchange('picking_id')
# def onchange_picking_id(self):
# # Add to candidate pickings the default picking. We are in a wizard
# # view, so for create a candidate picking with the same default picking
# # we need create it in this onchange
# self._set_default_picking()
@api.onchange('picking_id')
def onchange_picking_id(self):
if self.picking_id:
self.pack_operation_ids = [
(6, 0, self.picking_id.pack_operation_ids.ids)]
products_in_picking = self.picking_id.pack_operation_ids.mapped(
'product_id')
return {'domain': {'product_id': [
('id', 'in', products_in_picking.ids)]}}

def action_done(self):
if self.check_done_conditions():
Expand All @@ -142,6 +134,17 @@ def action_manual_entry(self):
self.action_done()
return result

def action_picking_validate(self):
if self.product_qty_done != self.product_uom_qty:
raise ValidationError(_(
"Please complete the picking before validating it"))
self.picking_id.do_new_transfer()
self.barcode = False
self._set_message_info(
'success',
_('Picking has been validated successfully'))
return {'type': 'ir.actions.client', 'tag': 'history_back'}

def _prepare_pack_operation_values(self, candidate_move, available_qty):
pack_lot_ids = self.env['stock.pack.operation.lot'].search(
[('lot_id', '=', self.lot_id.id)]).ids
Expand Down Expand Up @@ -171,34 +174,6 @@ def _prepare_stock_pack_operation_domain(self):
domain.append(('picking_id', '=', self.picking_id.id))
return domain

# def _set_candidate_pickings(self, candidate_pickings):
# # vals = [(5, 0, 0)]
# # vals.extend([(0, 0, {
# # 'picking_id': p.id,
# # }) for p in candidate_pickings])
# # self.candidate_picking_ids = vals
# self.env['wiz.candidate.picking'].search([]).unlink()
# for picking in candidate_pickings:
# self.env['wiz.candidate.picking'].create({
# 'picking_id': picking.id,
# })

# def _search_candidate_pickings(self, operations=False):
# if not operations:
# operations = self.env['stock.pack.operation'].search(
# self._prepare_stock_pack_operation_domain())
# if not self.picking_id:
# candidate_pickings = operations.mapped('picking_id')
# candidate_pickings_count = len(candidate_pickings)
# if candidate_pickings_count > 1:
# self._set_candidate_pickings(candidate_pickings)
# return False
# if candidate_pickings_count == 1:
# self.picking_id = candidate_pickings
# self._set_candidate_pickings(candidate_pickings)
# _logger.info('No picking assigned')
# return True

def _process_stock_move_line(self):
"""
Search assigned or confirmed stock moves from a picking operation type
Expand Down Expand Up @@ -272,12 +247,6 @@ def _process_stock_move_line(self):
self.picking_product_qty = sum(operations.mapped('qty_done'))
return move_lines_dic

# def _candidate_picking_selected(self):
# if self.candidate_picking_id:
# return self.candidate_picking_id.picking_id
# else:
# return self.env['stock.picking'].browse()

def check_done_conditions(self):
res = super(WizStockBarcodesReadPicking, self).check_done_conditions()
if self.product_id.tracking != 'none' and not self.lot_id:
Expand All @@ -287,14 +256,6 @@ def check_done_conditions(self):
self._set_message_info(
'info', _('Please, select the picking'))
return False
# if not self._search_candidate_pickings():
# self._set_message_info(
# 'info', _('Click on picking pushpin to lock it'))
# return False
# if self.picking_id != self._candidate_picking_selected():
# self._set_message_info(
# 'info', _('Click on picking pushpin to lock it'))
# return False
return res

def _prepare_scan_log_values(self, log_detail=False):
Expand Down Expand Up @@ -330,4 +291,6 @@ def action_undo_last_scan(self):
log_scan = first(self.scan_log_ids.filtered(
lambda x: x.create_uid == self.env.user))
self.remove_scanning_log(log_scan)
self.pack_operation_ids = [
(6, 0, self.picking_id.pack_operation_ids.ids)]
return res
59 changes: 49 additions & 10 deletions stock_barcodes/wizard/stock_barcodes_read_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,23 +96,62 @@
<field name="model">wiz.stock.barcodes.read.picking</field>
<field name="inherit_id" ref="stock_barcodes.view_stock_barcodes_read_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='manual_entry']" position="after">
<label for="confirmed_moves">
Confirmed moves allowed
</label>
<field name="confirmed_moves" widget="boolean_toggle"/>
</xpath>
<!-- <xpath expr="//field[@name='manual_entry']" position="after">-->
<!-- <label for="confirmed_moves">-->
<!-- Confirmed moves allowed-->
<!-- </label>-->
<!-- <field name="confirmed_moves" widget="boolean_toggle"/>-->
<!-- </xpath>-->
<field name="product_qty" position="after">
<field name="picking_product_qty"/>
</field>
<field name="location_id" position="after">
<field name="picking_type_code" invisible="1" force_save="1"/>
<field name="picking_id" widget="selection"/>
<field name="product_uom_qty" attrs="{'invisible': [('picking_id', '=', False)]}"/>
<field name="product_qty_reserved" attrs="{'invisible': [('picking_id', '=', False)]}"/>
<field name="product_qty_done" attrs="{'invisible': [('picking_id', '=', False)]}"/>
<!-- <field name="candidate_picking_id" attrs="{'invisible': [('candidate_picking_id', '=', False)]}"/>-->
</field>
<field name="product_qty" position="after">
<field name="picking_product_qty"/>
<field name="pack_operation_ids" mode="tree,kanban" options="{'no_open': True}"
attrs="{'invisible': [('picking_id', '=', False)]}">
<tree>
<field name="product_id"/>
<field name="product_qty"/>
</tree>
<kanban class="o_kanban_mobile">
<field name="product_id"/>
<field name="product_qty"/>
<templates>
<t t-name="kanban-box">
<div t-attf-class="oe_kanban_card"
style="background-color:lavender;border: 1px solid transparent;">
<div class="row">
<div class="col-xs-8">
<strong>
<span><t t-esc="record.product_id.value"/></span>
</strong>
</div>
<div class="col-xs-4">
<strong>
<span class="pull-right text-right">
<t t-esc="record.product_qty.value"/>
</span>
</strong>
</div>
</div>
</div>
</t>
</templates>
</kanban>
</field>
<!-- <field name="candidate_picking_id" attrs="{'invisible': [('candidate_picking_id', '=', False)]}"/>-->
</field>
<xpath expr="//group[@name='manual_entry']" position="after">
<group name="validate_picking">
<button name="action_picking_validate" type="object" string="Validate picking"
attrs="{'invisible': [('picking_id', '=', False)]}" icon="fa-check"
class="btn-primary"/>
</group>
</xpath>
</field>
</record>

Expand Down
8 changes: 4 additions & 4 deletions stock_barcodes/wizard/stock_barcodes_read_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<field name="res_model_id" invisible="1"/>
<field name="res_id" invisible="1"/>
<field name="_barcode_scanned" widget="barcode_handler" invisible="1"/>
<group>
<group name="location">
<field name="location_id" options="{'no_create': True}"
attrs="{'readonly': [('manual_entry', '=', False)], 'required': [('manual_entry', '=', True)]}"
force_save="1"/>
Expand All @@ -50,16 +50,16 @@
<button class="oe_link" string="New lot" type="action" name="%(action_stock_barcodes_new_lot)d" icon="fa-plus" context="{'default_product_id': product_id}"/>
</group>
</group>
<group>
<group name="product_group">
<field name="product_id" options="{'no_create': True}"
attrs="{'required': [('manual_entry', '=', True)]}"
force_save="1"/>
force_save="1" widget="selection"/>
<field name="packaging_id" options="{'no_create': True}" domain="[('product_id', '=', product_id)]" attrs="{'readonly': [('manual_entry', '=', False)]}" force_save="1" groups="product.group_stock_packaging"/>
<field name="packaging_qty" attrs="{'invisible': ['|', ('packaging_id', '=', False), ('manual_entry', '=', False)], 'readonly': [('manual_entry', '=', False)]}" force_save="1" widget="FieldFloatNumericMode"/>
<field name="product_qty" attrs="{'invisible': [('manual_entry', '=', False)], 'readonly': [('manual_entry', '=', False)]}" force_save="1" widget="FieldFloatNumericMode"/>
</group>
<group/>
<group>
<group name="manual_entry">
<button name="action_manual_entry" type="object" string="Manual entry" icon="fa-plus"
attrs="{'invisible': [('manual_entry', '=', False)]}"
class="btn-primary"
Expand Down

0 comments on commit 1a28667

Please sign in to comment.