Skip to content

Commit

Permalink
Merge PR #1792 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by alexis-via
  • Loading branch information
OCA-git-bot committed Jan 14, 2025
2 parents 61e6526 + b53dcc3 commit 7748818
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 12 deletions.
1 change: 1 addition & 0 deletions product_expiry_simple/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from . import wizards
2 changes: 2 additions & 0 deletions product_expiry_simple/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
"views/product_template.xml",
"views/stock_lot.xml",
"views/stock_quant.xml",
"views/stock_move.xml",
"views/stock_move_line.xml",
"views/stock_picking.xml",
"wizards/stock_assign_serial_view.xml",
],
"installable": True,
}
1 change: 1 addition & 0 deletions product_expiry_simple/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
from . import stock_lot
from . import stock_quant
from . import stock_move_line
from . import stock_move
from . import stock_picking
28 changes: 28 additions & 0 deletions product_expiry_simple/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockMove(models.Model):
_inherit = "stock.move"

# Add fields for the feature that generate serial numbers from first SN + Number of SN
serial_expiry_date = fields.Date(string="Expiry Date")
product_use_expiry_date = fields.Boolean(related="product_id.use_expiry_date")

def _generate_serial_move_line_commands(self, lot_names, origin_move_line=None):
move_lines_commands = super()._generate_serial_move_line_commands(
lot_names, origin_move_line=origin_move_line
)
if self.product_id.use_expiry_date and self.serial_expiry_date:
for move_line_command in move_lines_commands:
move_line_command[2]["expiry_date"] = self.serial_expiry_date
return move_lines_commands

def action_show_details(self):
action = super().action_show_details()
# empty field 'serial_expiry_date' on each run (like next_serial)
self.serial_expiry_date = False
return action
17 changes: 5 additions & 12 deletions product_expiry_simple/models/stock_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ class StockMoveLine(models.Model):

expiry_date = fields.Date()

# When you read the code of _create_and_assign_production_lot()
# you need the defects of that method:
# 1. it's not possible to inherit the creation of the lot
# 2. it creates one lot per company/product/lot_name
# On that second point, we can consider that, for a particular product,
# lot X will always have the same expiry_date

def _assign_production_lot(self, lot):
res = super()._assign_production_lot(lot)
if self[0].expiry_date:
self.lot_id.write({"expiry_date": self[0].expiry_date})
return res
def _get_value_production_lot(self):
vals = super()._get_value_production_lot()
if self.product_id.use_expiry_date:
vals["expiry_date"] = self.expiry_date
return vals
24 changes: 24 additions & 0 deletions product_expiry_simple/views/stock_move.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2024 Akretion France (https://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>

<record id="view_stock_move_operations" model="ir.ui.view">
<field name="name">product_expiry_simple.stock.move.form</field>
<field name="model">stock.move</field>
<field name="inherit_id" ref="stock.view_stock_move_operations" />
<field name="arch" type="xml">
<field name="next_serial" position="after">
<field name="product_use_expiry_date" invisible="1" />
<field
name="serial_expiry_date"
attrs="{'invisible': ['|', ('display_assign_serial', '=', False), ('product_use_expiry_date', '=', False)]}"
/>
</field>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions product_expiry_simple/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_assign_serial
22 changes: 22 additions & 0 deletions product_expiry_simple/wizards/stock_assign_serial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 Akretion France (https://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockAssignSerialNumbers(models.TransientModel):
_inherit = "stock.assign.serial"

serial_expiry_date = fields.Date(string="Expiry Date")
product_use_expiry_date = fields.Boolean(
related="move_id.product_id.use_expiry_date"
)

def generate_serial_numbers(self):
self.ensure_one()
if self.product_use_expiry_date and self.serial_expiry_date:
self.move_id.serial_expiry_date = self.serial_expiry_date
else:
self.move_id.serial_expiry_date = False
return super().generate_serial_numbers()
25 changes: 25 additions & 0 deletions product_expiry_simple/wizards/stock_assign_serial_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2024 Akretion France (https://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>


<record id="view_assign_serial_numbers" model="ir.ui.view">
<field name="model">stock.assign.serial</field>
<field name="inherit_id" ref="stock.view_assign_serial_numbers" />
<field name="arch" type="xml">
<field name="next_serial_number" position="after">
<field
name="serial_expiry_date"
attrs="{'invisible': [('product_use_expiry_date', '=', False)]}"
/>
<field name="product_use_expiry_date" invisible="1" />
</field>
</field>
</record>


</odoo>

0 comments on commit 7748818

Please sign in to comment.