Skip to content

Commit 6556b5d

Browse files
Update pickup_request.py and related improvements
1 parent 9d5be72 commit 6556b5d

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"python.analysis.typeCheckingMode": "basic",
32
"python.analysis.extraPaths": [
43
"/workspaces/ssh-git-github.com-odoo-odoo.git-8.0"
54
]

records_management/models/pickup_request.py

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,4 @@
1-
try:
2-
from odoo import fields, models, api
3-
except ImportError:
4-
# Fallbacks for environments without Odoo
5-
class DummyField:
6-
def __init__(self, *args, **kwargs): pass
7-
@staticmethod
8-
def from_string(val): return val
9-
@staticmethod
10-
def today(): return '1970-01-01'
11-
class DummyMeta(type):
12-
def __getattr__(self, name):
13-
return DummyField
14-
class fields(metaclass=DummyMeta):
15-
Many2one = DummyField
16-
Date = DummyField
17-
Selection = DummyField
18-
Many2many = DummyField
19-
class models(metaclass=DummyMeta):
20-
class Model(metaclass=DummyMeta):
21-
pass
22-
class DummyApi:
23-
@staticmethod
24-
def constrains(*args, **kwargs):
25-
def decorator(func): return func
26-
return decorator
27-
@staticmethod
28-
def onchange(*args, **kwargs):
29-
def decorator(func): return func
30-
return decorator
31-
api = DummyApi()
32-
33-
try:
34-
from odoo.exceptions import ValidationError
35-
except ImportError:
36-
ValidationError = Exception # fallback for environments without odoo
1+
from odoo import models, fields, api
372

383
class PickupRequest(models.Model):
394
"""
@@ -54,7 +19,7 @@ class PickupRequest(models.Model):
5419
)
5520
request_date = fields.Date(
5621
string='Request Date',
57-
default=lambda self: fields.Date.today(),
22+
default=fields.Date.today,
5823
required=True,
5924
help="The date when the pickup is requested. Cannot be in the past."
6025
)
@@ -66,8 +31,34 @@ class PickupRequest(models.Model):
6631
item_ids = fields.Many2many(
6732
'stock.production.lot',
6833
string='Items',
34+
domain="[('customer_id', '=', customer_id)]",
6935
help="Items to be picked up. Only items belonging to the selected customer are allowed."
7036
)
37+
warehouse_id = fields.Many2one(
38+
'stock.warehouse',
39+
string='Warehouse',
40+
compute='_compute_warehouse',
41+
store=True
42+
)
43+
signature = fields.Binary(string='Signature')
44+
45+
@api.depends('item_ids')
46+
def _compute_warehouse(self):
47+
"""
48+
Compute the warehouse based on the selected items.
49+
Sets the warehouse_id field to the warehouse containing all selected items,
50+
if they are all located in the same warehouse.
51+
"""
52+
for record in self:
53+
quants = self.env['stock.quant'].search([
54+
('lot_id', 'in', record.item_ids.ids),
55+
('location_id.usage', '=', 'internal')
56+
])
57+
warehouses = quants.mapped('location_id.warehouse_id')
58+
if len(warehouses) == 1:
59+
record.warehouse_id = warehouses[0]
60+
else:
61+
record.warehouse_id = False
7162

7263
@api.constrains('request_date')
7364
def _check_request_date(self):

0 commit comments

Comments
 (0)