Skip to content

Commit 883b30d

Browse files
Update manifest dictionary
1 parent 4f4a23f commit 883b30d

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

manifest dictionary

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,129 @@
99
'installable': True,
1010
'application': True,
1111
}
12+
# Odoo manifest dictionary should be in __manifest__.py, not here.
13+
from odoo import fields, models, api, http
14+
from odoo.http import request
15+
16+
class StockProductionLot(models.Model):
17+
_inherit = 'stock.production.lot'
18+
19+
# Reference to the customer (res.partner) associated with this lot.
20+
customer_id = fields.Many2one('res.partner', string='Customer')
21+
22+
class ShreddingService(models.Model):
23+
_name = 'shredding.service'
24+
_description = 'Document Shredding Service'
25+
26+
customer_id = fields.Many2one('res.partner', string='Customer', required=True)
27+
service_date = fields.Date(string='Service Date', default=fields.Date.today)
28+
service_type = fields.Selection([
29+
('bin', 'Bin Shredding'),
30+
('box', 'Box Shredding')
31+
], string='Service Type', required=True)
32+
bin_ids = fields.Many2many(
33+
'stock.production.lot', string='Serviced Bins',
34+
domain=[('product_id.name', '=', 'Shredding Bin')]
35+
)
36+
box_quantity = fields.Integer(string='Number of Boxes')
37+
shredded_box_ids = fields.Many2many(
38+
'stock.production.lot', string='Shredded Boxes',
39+
domain=[('customer_id', '!=', False)]
40+
)
41+
audit_barcodes = fields.Text(string='Audit Barcodes')
42+
total_charge = fields.Float(string='Total Charge', compute='_compute_total_charge')
43+
timestamp = fields.Datetime(string='Service Timestamp', default=fields.Datetime.now)
44+
latitude = fields.Float(string='Latitude')
45+
longitude = fields.Float(string='Longitude')
46+
attachment_ids = fields.Many2many('ir.attachment', string='Attachments')
47+
map_display = fields.Char(compute='_compute_map_display', string='Map')
48+
49+
@api.depends('service_type', 'bin_ids', 'box_quantity', 'shredded_box_ids')
50+
def _compute_total_charge(self):
51+
for record in self:
52+
if record.service_type == 'bin':
53+
record.total_charge = len(record.bin_ids) * 10.0
54+
elif record.service_type == 'box':
55+
qty = record.box_quantity or len(record.shredded_box_ids)
56+
record.total_charge = qty * 5.0
57+
else:
58+
record.total_charge = 0.0
59+
60+
@api.depends('latitude', 'longitude')
61+
def _compute_map_display(self):
62+
for record in self:
63+
record.map_display = f"{record.latitude},{record.longitude}"
64+
65+
class PickupRequest(models.Model):
66+
"""
67+
Represents a pickup request for items associated with a customer.
68+
69+
Model Fields:
70+
customer_id (Many2one): Reference to the customer (res.partner) making the pickup request. Required.
71+
request_date (Date): The date the pickup request was created. Defaults to today's date.
72+
state (Selection): The current status of the pickup request. Possible values are:
73+
- 'draft': Draft
74+
- 'confirmed': Confirmed
75+
- 'done': Done
76+
Defaults to 'draft'.
77+
item_ids (Many2many): List of items (stock.production.lot) included in the pickup request.
78+
Only items belonging to the selected customer can be chosen.
79+
"""
80+
_name = 'pickup.request'
81+
_description = 'Pickup Request'
82+
83+
customer_id = fields.Many2one('res.partner', string='Customer', required=True)
84+
request_date = fields.Date(string='Request Date', default=fields.Date.today)
85+
state = fields.Selection([
86+
('draft', 'Draft'),
87+
('confirmed', 'Confirmed'),
88+
('done', 'Done')
89+
], default='draft', string='Status')
90+
item_ids = fields.Many2many(
91+
'stock.production.lot', string='Items',
92+
domain="[('customer_id', '=', customer_id)]"
93+
)
94+
95+
class InventoryPortal(http.Controller):
96+
@http.route('/my/inventory', type='http', auth='user', website=True)
97+
def inventory(self, **kw):
98+
"""
99+
Retrieves and renders the inventory of stock quants associated with the current user's partner.
100+
101+
Returns:
102+
werkzeug.wrappers.Response: The rendered inventory template with the relevant stock quants.
103+
"""
104+
partner = request.env.user.partner_id
105+
if not partner:
106+
return request.not_found()
107+
serials = request.env['stock.production.lot'].search([('customer_id', '=', partner.id)])
108+
quants = request.env['stock.quant'].search([
109+
('lot_id', 'in', serials.ids),
110+
('location_id.usage', '=', 'internal')
111+
])
112+
return request.render('records_management.inventory_template', {'quants': quants})
113+
114+
@http.route('/my/request_pickup', type='http', auth='user', website=True, methods=['GET', 'POST'], csrf=True)
115+
def request_pickup(self, **post):
116+
partner = request.env.user.partner_id
117+
if not partner:
118+
return request.not_found()
119+
if request.httprequest.method == 'POST':
120+
item_ids = request.httprequest.form.getlist('item_ids')
121+
try:
122+
item_ids = [int(id) for id in item_ids]
123+
except (ValueError, TypeError):
124+
item_ids = []
125+
items = request.env['stock.production.lot'].search([
126+
('id', 'in', item_ids),
127+
('customer_id', '=', partner.id)
128+
])
129+
if items:
130+
request.env['pickup.request'].create({
131+
'customer_id': partner.id,
132+
'item_ids': [(6, 0, items.ids)],
133+
})
134+
return request.redirect('/my/inventory')
135+
# Render the pickup request form for GET requests
136+
serials = request.env['stock.production.lot'].search([('customer_id', '=', partner.id)])
137+
return request.render('records_management.pickup_request_form', {'serials': serials})

0 commit comments

Comments
 (0)