Added Employee Custody to Purchase Request

This commit is contained in:
younes 2025-05-08 16:00:53 +01:00
parent 5a9139c8a8
commit 0bb1a7b979
1 changed files with 23 additions and 17 deletions

View File

@ -4,6 +4,7 @@ from odoo import api, fields, models, _
from odoo.tools.float_utils import float_is_zero
from dateutil.relativedelta import relativedelta
class AccountMove(models.Model):
_inherit = 'account.move'
@ -32,6 +33,7 @@ class AccountMove(models.Model):
vals['purpose'] = po.purpose
super(AccountMove, self).write(vals)
class PurchaseOrderCustom(models.Model):
_inherit = "purchase.order"
@ -41,16 +43,15 @@ class PurchaseOrderCustom(models.Model):
requisition_state = fields.Selection(related="requisition_id.state")
requisition_type_exclusive = fields.Selection(related="requisition_id.type_exclusive")
@api.depends('requisition_id')
def _compute_has_requisition(self):
for record in self:
record.has_requisition = bool(record.requisition_id)
def read(self, records):
return super(PurchaseOrderCustom, self.sudo()).read(records)
@api.depends('invoice_ids','invoice_count')
@api.depends('invoice_ids', 'invoice_count')
def _compute_amount(self):
for order in self:
billed_amount = 0.0
@ -58,7 +59,7 @@ class PurchaseOrderCustom(models.Model):
billed_amount += invoice.amount_total
currency = order.currency_id or order.partner_id.property_purchase_currency_id or \
self.env.company.currency_id
self.env.company.currency_id
order.update({
'billed_amount': currency.round(billed_amount),
'remaining_amount': order.amount_total - billed_amount,
@ -75,10 +76,11 @@ class PurchaseOrderCustom(models.Model):
data.state = 'draft'
return data
attach_no = fields.Integer(compute='get_attachments')
res_id = fields.Integer()
res_model = fields.Char()
state = fields.Selection([
('wait', 'Waiting To Be Signed'),
('unsign', 'UnSign'),
@ -131,16 +133,15 @@ class PurchaseOrderCustom(models.Model):
already_voted = fields.Boolean(compute="_compute_already_voted")
purchase_request_employee_id = fields.Many2one(related="request_id.employee_id")
@api.depends('request_id')
def _compute_department_id(self):
for rec in self:
rec.department_id = rec.request_id.department_id
def _recompute_all_department_id(self):
for rec in self.sudo().search([('request_id', '!=', False), ('department_id', '=', False)]):
rec._compute_department_id()
def get_attachments(self):
# Check if multiple records are passed, and handle them in a loop
if len(self) > 1:
@ -211,7 +212,7 @@ class PurchaseOrderCustom(models.Model):
def _prepare_invoice(self):
res = super(PurchaseOrderCustom, self)._prepare_invoice()
res.update({'purchase_id': self.id, 'res_id': self.id,'res_model': 'purchase.order'})
res.update({'purchase_id': self.id, 'res_id': self.id, 'res_model': 'purchase.order'})
return res
@api.onchange('type')
@ -435,7 +436,6 @@ class PurchaseOrderCustom(models.Model):
# rec.date_order) <= fields.Date.from_string(x.date_to))
# return res
def print_quotation(self):
if self.state in ['wait']:
self.write({'state': "sent"})
@ -606,7 +606,7 @@ class PurchaseOrderCustom(models.Model):
def button_confirm(self):
for order in self:
if order.state not in ['draft', 'sent', 'sign','wait']:
if order.state not in ['draft', 'sent', 'sign', 'wait']:
continue
order._add_supplier_to_product()
# Deal with double validation process
@ -626,7 +626,11 @@ class PurchaseOrderCustom(models.Model):
amount = sum(item.purchase_remain for item in budget_lines)
amount += line.price_subtotal
budget_lines.write({'purchase_remain': amount})
budget_lines.write({'reserve': abs(line.price_subtotal - budget_lines.reserve)})
for b_line in budget_lines.filtered(
lambda b: line.account_analytic_id.id in b.general_budget_id.account_ids.ids):
b_line.reserve = abs(line.price_subtotal - b_line.reserve)
# b_line.write({'reserve': abs(line.price_subtotal - b_line.reserve)})
# budget_lines.write({'reserve': abs(line.price_subtotal - budget_lines.reserve)})
# if order.requisition_id.id:
# order.requisition_id.state = 'done'
@ -639,6 +643,7 @@ class PurchaseOrderCustom(models.Model):
Move document to Wait state
"""
self.write({'state': 'wait', 'is_signed': False})
@api.depends('committe_members')
def _compute_already_voted(self):
for rec in self:
@ -675,7 +680,6 @@ class PurchaseOrderCustom(models.Model):
'context': {'default_order_id': self.id}
}
def action_recommend(self):
for order in self:
order.recommendation_order = True
@ -713,14 +717,16 @@ class PurchaseOrderCustom(models.Model):
if not account_id:
raise ValidationError(
_("This product has no expense account") + ': {}'.format(rec.product_id.name))
budget_post = self.env['account.budget.post'].search([]).filtered(lambda x: account_id in x.account_ids)
budget_post = self.env['account.budget.post'].search([]).filtered(
lambda x: account_id in x.account_ids)
if len(budget_post.ids) > 1:
raise ValidationError(
_("The Expense account %s is assigned to more than one budget position %s")%(account_id.name,[x.name for x in budget_post]))
_("The Expense account %s is assigned to more than one budget position %s") % (
account_id.name, [x.name for x in budget_post]))
if analytic_account:
budget_lines = self.env['crossovered.budget.lines'].search(
[('analytic_account_id', '=', analytic_account.id),
('general_budget_id','in',budget_post.ids),
('general_budget_id', 'in', budget_post.ids),
('crossovered_budget_id.state', '=', 'done'),
('crossovered_budget_id.date_from', '<=', self.date_order),
('crossovered_budget_id.date_to', '>=', self.date_order)])
@ -821,7 +827,7 @@ class Attachment(models.Model):
class ProductCustom(models.Model):
_inherit = 'product.product'
_inherit = 'product.product'
@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):