Merge pull request #550 from expsa/purchase_req_chgs

Purchase req chgs
This commit is contained in:
eslam 2024-08-06 07:54:19 +03:00 committed by GitHub
commit d104574fd1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 43 additions and 8 deletions

View File

@ -19,6 +19,7 @@ class PurchaseRequest(models.Model):
('waiting', 'In Purchase'),('employee', 'Employee Delivery'),('done', 'Done'), ('cancel', 'Cancel'), ('refuse', 'Refuse')], default="draft",
tracking=True,copy=False )
show_emp_button=fields.Boolean(compute='show_employee_button',copy=False)
show_approve_warehouse=fields.Boolean("Approve Warehouse",compute='show_approve_warehouse_button')
def show_employee_button(self):
"""show only for the create employee"""
@ -27,6 +28,14 @@ class PurchaseRequest(models.Model):
if rec.create_uid.id == self.env.user.id and rec.state == 'employee':
rec.show_emp_button=True
@api.depends("warehouse_id")
def show_approve_warehouse_button(self):
"""show only for the show aaprove warhouse employee"""
for rec in self:
rec.show_approve_warehouse=False
if rec.warehouse_id.manager_id.user_id.id == self.env.user.id and rec.state == 'warehouse':
rec.show_approve_warehouse=True
def compute_edit_locations(self):
"""Compute For Group Edit Warehouse/Locations"""
@ -231,11 +240,11 @@ class PurchaseRequest(models.Model):
elif vals['state'] == 'warehouse':
# stock_group = self.env.ref('stock.group_stock_manager')
warehouse=self.env['stock.warehouse'].sudo().search([('department_id', '=', self.department_id.id)])
stock_employee=False
if warehouse and warehouse.manager_id:
stock_users = warehouse.manager_id
if stock_users:
stock_employee=self.env['hr.employee'].search([('user_id','=',stock_users.id)],limit=1)
if stock_employee and stock_users.partner_id.id:
stock_employee = warehouse.manager_id
if stock_employee and stock_employee.user_id.partner_id.id:
if self.env.user.partner_id.lang=='ar_001':
body = 'عزيزى %s موافقتك مطلوبة على %s ' % (stock_employee.name, self.name)
else:
@ -244,7 +253,7 @@ class PurchaseRequest(models.Model):
message_type='notification',
author_id=self.env.user.partner_id.id, sticky=True,
subtype_id=self.env.ref("mail.mt_comment").id,
partner_ids=[stock_users.partner_id.id])
partner_ids=[stock_employee.user_id.partner_id.id])
elif vals['state'] == 'waiting':
purchase_group = self.env.ref('purchase.group_purchase_manager')
purchase_users = self.env['res.users'].search([('groups_id', '=', purchase_group.id)])

View File

@ -4,5 +4,5 @@ from odoo import api, fields, models, _
class StockWarehouse(models.Model):
_inherit = 'stock.warehouse'
manager_id=fields.Many2one("res.users",string="Warehouse Manager")
manager_id=fields.Many2one("hr.employee",string="Warehouse Manager",domain="[('department_id', '=',department_id)]",)
department_id=fields.Many2one("hr.department",string="Warehouse Branch")

View File

@ -20,6 +20,7 @@
<field name="view_location_id" invisible="1"/>
<field name="edit_locations" invisible="1"/>
<field name="show_emp_button" invisible="1"/>
<field name="show_approve_warehouse" invisible="0"/>
<div>
<label for="warehouse_id"/>
<field name="warehouse_id" attrs="{'readonly':['|',('edit_locations' , '=' , False),('state' , '!=' , 'warehouse')]}" groups="stock.group_stock_user,stock.group_stock_manager"/>
@ -42,9 +43,10 @@
<xpath expr="//button[@name='action_confirm']" position="after">
<button name="action_confirm_picking"
type="object" string="Confirm" states="warehouse" class="oe_highlight" groups="stock.group_stock_user,stock.group_stock_manager"/>
type="object" string="Confirm"
attrs="{'invisible':[('show_approve_warehouse' , '=' , False)]}" class="oe_highlight" groups="stock.group_stock_user,stock.group_stock_manager"/>
<button name="action_available_qty"
type="object" string="Available Quantity" states="warehouse" class="oe_highlight" groups="stock.group_stock_user,stock.group_stock_manager"/>
type="object" string="Available Quantity" attrs="{'invisible':[('show_approve_warehouse' , '=' , False)]}" class="oe_highlight" groups="stock.group_stock_user,stock.group_stock_manager"/>
</xpath>
<xpath expr="//field[@name='line_ids']/tree[1]/field[@name='qty']" position="after">
<field name="available_qty" readonly="1" attrs="{'column_invisible': [('parent.state', '!=', 'warehouse')]}"/>

View File

@ -72,6 +72,25 @@ class PurcahseRefues(models.TransientModel):
line.qty_purchased=line.qty
self.request_id.write({'state': 'waiting'})
def convert_purchase(self):
picking_id = self.env.ref('purchase_custom_stock.stock_picking_type_stock')
picking_vals = {
"picking_type_id": self.env.ref('purchase_custom_stock.stock_picking_type_stock').id,
"origin": self.request_id.name,
"location_id": self.request_id.location_id.id,
"location_dest_id": picking_id.default_location_dest_id.id
}
move_vals = []
for line in self.request_line_ids.filtered(lambda line: line.product_id.type == 'product'):
move_vals.append((0, 0, {
"product_id": line.product_id.id,
"name": line.product_id.name,
"product_uom": line.product_id.uom_id.id,
'product_uom_qty': line.qty,
}))
picking_vals.update({'move_lines': move_vals})
picking_id = self.env['stock.picking'].create(picking_vals)
self.request_id.picking_id = picking_id.id
for line in self.request_line_ids:
line.qty_purchased=line.qty
self.request_id.write({'state': 'waiting'})

View File

@ -415,6 +415,11 @@
<field name="product_id" context="{'product_id':parent.line_ids}"
domain="[('purchase_ok', '=', True),('categ_id','in',parent.category_ids)]"/>
</xpath>
<xpath expr="//notebook/page[1]/field[@name='line_ids']/tree[1]/field[@name='account_analytic_id']"
position="replace">
<field name="account_analytic_id" domain="['|', ('company_id', '=', False), ('company_id', '=', parent.company_id)]" groups="analytic.group_analytic_accounting"/>
</xpath>
<xpath expr="//notebook/page[1]/field[@name='line_ids']/tree[1]/field[@name='account_analytic_id']"
position="after">
<field name="name"/>