Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] stock_voucher: _bom_find error #375

Open
wants to merge 6 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stock_ux/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
##############################################################################
{
'name': 'Stock UX',
'version': "15.0.1.3.0",
'version': "15.0.1.5.0",
'category': 'Warehouse Management',
'sequence': 14,
'summary': '',
Expand Down
11 changes: 10 additions & 1 deletion stock_ux/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class StockMove(models.Model):
related='picking_id.partner_id',
)

origin_description = fields.Char(compute="_compute_origin_description")

@api.depends(
'move_line_ids.qty_done',
'move_line_ids.lot_id',
Expand All @@ -42,6 +44,13 @@ def _compute_used_lots(self):
rec.move_line_ids.filtered('lot_id').mapped(
lambda x: "%s (%s)" % (x.lot_id.name, x.qty_done)))

def _compute_origin_description(self):
for rec in self:
if rec.sale_line_id:
rec.origin_description = rec.sale_line_id.name
else:
rec.origin_description = False

def set_all_done(self):
self.mapped('move_line_ids').set_all_done()
for rec in self.filtered(lambda x: not x.move_line_ids):
Expand Down Expand Up @@ -174,4 +183,4 @@ def check_cancel(self):
return
if self.filtered(
lambda x: x.picking_id and x.state == 'cancel' and not self.user_has_groups('stock_ux.allow_picking_cancellation')):
raise ValidationError("Only User with 'Picking cancelation allow' rights can cancel pickings")
raise ValidationError("Only User with 'Picking cancelation allow' rights can cancel pickings")
20 changes: 15 additions & 5 deletions stock_ux/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class StockMoveLine(models.Model):
related="move_id.name",
related_sudo=False,
)
origin_description = fields.Char(
related="move_id.origin_description",
)

def set_all_done(self):
precision = self.env['decimal.precision'].precision_get(
Expand Down Expand Up @@ -86,9 +89,12 @@ def _check_quantity(self):
return
self.mapped('move_id')._check_quantity()
# We verify the case that does not have 'move_id' to restrict how does_check_quantity() in moves
if any(self.filtered(lambda x: not x.move_id and x.picking_id.picking_type_id.block_additional_quantity)):
raise ValidationError(
_('You can not transfer more than the initial demand!'))
# Tuve que comentar este código porque tenía un efecto no deseado en la lectura de codigos de barra
# No permitía editar las cantidades de productos que se marcaban como hechos. Eso hacia que si leías más cantidad
# de lo que indicaba la orden de recepción NO lo puedas modificar
# if any(self.filtered(lambda x: not x.move_id and x.picking_id.picking_type_id.block_additional_quantity)):
# raise ValidationError(
# _('You can not transfer more than the initial demand!'))

@api.model
def create(self, values):
Expand All @@ -104,6 +110,10 @@ def _get_aggregated_product_quantities(self, **kwargs):
aggregated_move_lines = super()._get_aggregated_product_quantities(**kwargs)
if bool(self.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin', 'False')) == True:
for line in aggregated_move_lines:
moves = self.filtered(lambda sml: sml.product_id == aggregated_move_lines[line]['product']).mapped('move_id')
aggregated_move_lines[line]['name'] =', '.join(moves.mapped('name'))
moves = self.filtered(
lambda sml: sml.product_id == aggregated_move_lines[line]['product']
).mapped('move_id').filtered(lambda m: m.origin_description)
if moves:
aggregated_move_lines[line]['description'] = False
aggregated_move_lines[line]['name'] =', '.join(moves.mapped('origin_description'))
return aggregated_move_lines
20 changes: 7 additions & 13 deletions stock_ux/views/report_deliveryslip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@
</p>
</table>
<xpath expr="//table[@name='stock_move_table']/tbody/tr/td[1]" position="attributes">
<attribute name="t-if">o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin', 'False') == 'False'</attribute>
<attribute name="t-if">o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin', 'False') == 'False' or not move.origin_description</attribute>
</xpath>
<xpath expr="//table[@name='stock_move_table']/tbody/tr/td[1]" position="after">
<td t-if="o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin') == 'True'">
<span t-field="move.name"/>
<p t-if="move.description_picking != move.product_id.name">
<span t-field="move.description_picking"/>
</p>
<td t-if="o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin') == 'True' and move.origin_description">
<span t-field="move.origin_description"/>
</td>
</xpath>

<!-- Filtramos los stock_move en estado cancelado porque nosotros habilitamos la cancelacion de los mismos,
esto desde el lado de Odoo no se puede lograr -->
<xpath expr="//t[@t-set='lines']" position="after">
Expand All @@ -28,14 +25,11 @@

<template id="stock_report_delivery_has_serial_move_line" inherit_id="stock.stock_report_delivery_has_serial_move_line">
<xpath expr="//td[1]" position="attributes">
<attribute name="t-if">o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin', 'False') == 'False'</attribute>
<attribute name="t-if">o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin', 'False') == 'False' or not move_line.origin_description</attribute>
</xpath>
<xpath expr="//td[1]" position="after">
<td t-if="o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin') == 'True'">
<span t-field="move_line.move_id.name"/>
<p t-if="move_line.move_id.description_picking != move_line.product_id.name">
<span t-field="move_line.move_id.description_picking"/>
</p>
<td t-if="o.env['ir.config_parameter'].sudo().get_param('stock_ux.delivery_slip_use_origin') == 'True' and move_line.origin_description">
<span t-field="move_line.origin_description"/>
</td>
</xpath>
</template>
Expand Down
2 changes: 1 addition & 1 deletion stock_ux/views/stock_move_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<field name="arch" type="xml">
<field name="product_id" position="after">
<field name="description_picking" optional="hide"/>
<field name="name" string="Descripción de origen" optional="hide"/>
<field name="origin_description" string="Descripción de origen" optional="hide"/>
</field>
<field name="qty_done" position="after">
<button name="set_all_done" title="Set all Done" type="object" icon="fa-check" states="confirmed,assigned,waiting,partially_available"/>
Expand Down
2 changes: 1 addition & 1 deletion stock_ux/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<attribute name="attrs"></attribute>
</field>
<field name="description_picking" position="after">
<field name="name" string="Descripción de origen" optional="hide"/>
<field name="origin_description" string="Descripción de origen" optional="hide"/>
</field>
<div name="button_box">
<button name="add_picking_operation" class="oe_inline oe_right" icon="fa-list" type="object" string="Process Products" attrs="{'invisible': [('state', 'not in', ['confirmed', 'assigned'])]}"/>
Expand Down
18 changes: 12 additions & 6 deletions stock_voucher/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def _compute_declared_value(self):
if bom_enable:
for so_bom_line in stock_bom_lines.mapped('sale_line_id'):
bom = self.env['mrp.bom']._bom_find(
product=so_bom_line.product_id,
company_id=so_bom_line.company_id.id)
products=so_bom_line.product_id,
company_id=so_bom_line.company_id.id)[so_bom_line.product_id]
if bom and bom.type == 'phantom':
bom_moves = so_bom_line.move_ids & stock_bom_lines
done_avg = []
Expand All @@ -218,10 +218,16 @@ def _compute_declared_value(self):
picking_avg.append((
move.product_uom_qty / bom_quantity))
done_avg.append((move.quantity_done / bom_quantity))
picking_value += so_bom_line.price_reduce_taxexcl * (
sum(picking_avg) / len(picking_avg))
done_value += so_bom_line.price_reduce_taxexcl * (
sum(done_avg) / len(done_avg))
if len(picking_avg) == 0:
picking_value += so_bom_line.price_reduce_taxexcl
else:
picking_value += so_bom_line.price_reduce_taxexcl * (
sum(picking_avg) / len(picking_avg))
if len(done_avg) == 0:
done_value += so_bom_line.price_reduce_taxexcl
else:
done_value += so_bom_line.price_reduce_taxexcl * (
sum(done_avg) / len(done_avg))

declared_value = picking_value if inmediate_transfer\
else done_value
Expand Down