Skip to content

Commit

Permalink
Merge PR #72 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by andhit-r
  • Loading branch information
ssi-bot committed Aug 31, 2024
2 parents 372eba4 + 6caffd4 commit 276aeb2
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 14 deletions.
48 changes: 34 additions & 14 deletions ssi_stock/models/stock_production_lot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,25 @@ class StockProductionLot(models.Model):

@api.depends(
"stock_move_line_ids",
"stock_move_line_ids.date",
"stock_move_line_ids.move_id.state",
"tracking",
)
def _compute_serial_number_in_date(self):
for rec in self:
serial_number_in_date = False
if rec.tracking == "serial":
criteria = [("lot_id", "=", rec.id), ("state", "=", "done")]

first_move_line_id = self.env["stock.move.line"].search(
criteria, order="date, id", limit=1
def _compute_stock_move_line(self):
for record in self:
first_sml = last_sml = False
if record.tracking == "serial":
criteria = [
("lot_id", "=", record.id),
("move_id.state", "=", "done"),
]
smls = self.env["stock.move.line"].search(
criteria, order="date asc, id asc"
)
serial_number_in_date = first_move_line_id.date
rec.serial_number_in_date = serial_number_in_date
if len(smls) == 1:
first_sml = smls[0]
last_sml = smls[-1]
record.first_stock_move_line_id = first_sml
record.last_stock_move_line_id = last_sml

tracking = fields.Selection(related="product_id.tracking", store=True)
stock_move_line_ids = fields.One2many(
Expand All @@ -35,9 +39,25 @@ def _compute_serial_number_in_date(self):
string="Stock Move Lines",
copy=False,
)
first_stock_move_line_id = fields.Many2one(
string="First Stock Move Line",
comodel_name="stock.move.line",
compute="_compute_stock_move_line",
store=True,
)
last_stock_move_line_id = fields.Many2one(
string="Last Stock Move Line",
comodel_name="stock.move.line",
compute="_compute_stock_move_line",
store=True,
)
serial_number_in_date = fields.Datetime(
string="Incoming Date",
compute="_compute_serial_number_in_date",
compute_sudo=False,
store=False,
related="first_stock_move_line_id.date",
store=True,
)
serial_number_current_location_id = fields.Many2one(
string="Current Location",
related="last_stock_move_line_id.location_dest_id",
store=True,
)
54 changes: 54 additions & 0 deletions ssi_stock/views/stock_production_lot_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,52 @@
name="serial_number_in_date"
invisible="context.get('tracking') != 'serial'"
/>
<field
name="serial_number_current_location_id"
invisible="context.get('tracking') != 'serial'"
/>

</xpath>
</data>
</field>
</record>

<record id="view_production_lot_search" model="ir.ui.view">
<field name="name">stock.production.lot - search</field>
<field name="model">stock.production.lot</field>
<field name="inherit_id" ref="stock.search_product_lot_filter" />
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='product_id']" position="before">
<field
name="serial_number_in_date"
invisible="context.get('tracking') != 'serial'"
/>
<field
name="serial_number_current_location_id"
invisible="context.get('tracking') != 'serial'"
/>

</xpath>
<xpath expr="//group[1]" position="inside">
<filter
name="grp_serial_number_in_date"
invisible="context.get('tracking') != 'serial'"
string="Incoming Date"
context="{'group_by': 'serial_number_in_date'}"
/>
<filter
name="grp_serial_number_current_location_id"
invisible="context.get('tracking') != 'serial'"
string="Current Location"
context="{'group_by': 'serial_number_current_location_id'}"
/>
</xpath>
</data>
</field>
</record>


<record id="view_production_lot_form" model="ir.ui.view">
<field name="name">stock.production.lot - form</field>
<field name="model">stock.production.lot</field>
Expand All @@ -28,10 +69,23 @@
<data>
<xpath expr="//field[@name='product_id']" position="after">
<field name="tracking" invisible="1" />
<field
name="first_stock_move_line_id"
invisible="context.get('tracking') != 'serial'"
/>
<field
name="last_stock_move_line_id"
invisible="context.get('tracking') != 'serial'"
/>
<field
name="serial_number_in_date"
attrs="{'invisible': [('tracking', '!=', 'serial')]}"
/>
<field
name="serial_number_current_location_id"
invisible="context.get('tracking') != 'serial'"
/>

</xpath>
</data>
</field>
Expand Down

0 comments on commit 276aeb2

Please sign in to comment.