-
-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] product_expiry_simple: inherit stock.assign.serial wizard
Add ability to set expiry date when using the assign serial feature on a stock move
- Loading branch information
1 parent
71a9f8c
commit b53dcc3
Showing
9 changed files
with
109 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | ||
# 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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import stock_assign_serial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | ||
# 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
25
product_expiry_simple/wizards/stock_assign_serial_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | ||
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> |