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

[16.0][IMP] product_expiry_simple: inherit stock.assign.serial wizard #1792

Open
wants to merge 1 commit into
base: 16.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
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 <[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(

Check warning on line 16 in product_expiry_simple/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/models/stock_move.py#L16

Added line #L16 was not covered by tests
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

Check warning on line 22 in product_expiry_simple/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/models/stock_move.py#L21-L22

Added lines #L21 - L22 were not covered by tests

def action_show_details(self):
action = super().action_show_details()

Check warning on line 25 in product_expiry_simple/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/models/stock_move.py#L25

Added line #L25 was not covered by tests
# empty field 'serial_expiry_date' on each run (like next_serial)
self.serial_expiry_date = False
return action

Check warning on line 28 in product_expiry_simple/models/stock_move.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/models/stock_move.py#L27-L28

Added lines #L27 - L28 were not covered by tests
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 @@

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()

Check warning on line 15 in product_expiry_simple/models/stock_move_line.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/models/stock_move_line.py#L15

Added line #L15 was not covered by tests
if self.product_id.use_expiry_date:
vals["expiry_date"] = self.expiry_date
return vals

Check warning on line 18 in product_expiry_simple/models/stock_move_line.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/models/stock_move_line.py#L17-L18

Added lines #L17 - L18 were not covered by tests
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 <[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>
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 <[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()

Check warning on line 17 in product_expiry_simple/wizards/stock_assign_serial.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/wizards/stock_assign_serial.py#L17

Added line #L17 was not covered by tests
if self.product_use_expiry_date and self.serial_expiry_date:
self.move_id.serial_expiry_date = self.serial_expiry_date

Check warning on line 19 in product_expiry_simple/wizards/stock_assign_serial.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/wizards/stock_assign_serial.py#L19

Added line #L19 was not covered by tests
else:
self.move_id.serial_expiry_date = False
return super().generate_serial_numbers()

Check warning on line 22 in product_expiry_simple/wizards/stock_assign_serial.py

View check run for this annotation

Codecov / codecov/patch

product_expiry_simple/wizards/stock_assign_serial.py#L21-L22

Added lines #L21 - L22 were not covered by tests
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 <[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>
Loading