mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[MIG] Purchase policy
This commit is contained in:
committed by
Chanakya Soni
parent
d59834f518
commit
7b4e40d959
@@ -1,8 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2017-18 Eficent Business and IT Consulting Services S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||||
|
|
||||||
from openerp import api, fields, models
|
from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrder(models.Model):
|
class PurchaseOrder(models.Model):
|
||||||
@@ -24,6 +23,4 @@ class PurchaseOrder(models.Model):
|
|||||||
'product_uom': rma_line.uom_id.id,
|
'product_uom': rma_line.uom_id.id,
|
||||||
})
|
})
|
||||||
res.order_line = line
|
res.order_line = line
|
||||||
# TODO: maybe this line is not needed in v10:
|
|
||||||
res.date_planned = res._compute_date_planned()
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||||
|
|
||||||
from odoo import api, models
|
from odoo import api, fields, models
|
||||||
|
|
||||||
|
|
||||||
class PurchaseOrderLine(models.Model):
|
class PurchaseOrderLine(models.Model):
|
||||||
_inherit = "purchase.order.line"
|
_inherit = "purchase.order.line"
|
||||||
|
|
||||||
# TODO: to be removed on migration to v10:
|
|
||||||
# This is needed because odoo misspelled `store` in v9 :facepalm:
|
|
||||||
state = fields.Selection(related='order_id.state', store=True)
|
|
||||||
|
|
||||||
rma_line_id = fields.Many2one(
|
rma_line_id = fields.Many2one(
|
||||||
comodel_name='rma.order.line', string='RMA',
|
comodel_name='rma.order.line', string='RMA',
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||||
|
|
||||||
from openerp import api, fields, models, _
|
from odoo import api, fields, models, _
|
||||||
from openerp.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
|
||||||
|
|
||||||
class RmaOperation(models.Model):
|
class RmaOperation(models.Model):
|
||||||
|
|||||||
@@ -12,9 +12,12 @@ class RmaOrder(models.Model):
|
|||||||
def _compute_po_count(self):
|
def _compute_po_count(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
po_count = 0
|
po_count = 0
|
||||||
|
rma_line_po = []
|
||||||
for line in rec.rma_line_ids:
|
for line in rec.rma_line_ids:
|
||||||
po_count += len(self.env['purchase.order'].search(
|
rma_line_po += self.env['purchase.order'].search(
|
||||||
[('origin', '=', line.name)]).ids)
|
[('origin', '=', line.name)]).ids
|
||||||
|
if rma_line_po:
|
||||||
|
po_count = len(list(set(rma_line_po)))
|
||||||
rec.po_count = po_count
|
rec.po_count = po_count
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@@ -35,6 +38,9 @@ class RmaOrder(models.Model):
|
|||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
po_ids = self.env['purchase.order'].search(
|
po_ids = self.env['purchase.order'].search(
|
||||||
[('origin', '=', self.name)]).ids
|
[('origin', '=', self.name)]).ids
|
||||||
|
for line in self.rma_line_ids:
|
||||||
|
po_ids += self.env['purchase.order'].search(
|
||||||
|
[('origin', '=', line.name)]).ids
|
||||||
if not po_ids:
|
if not po_ids:
|
||||||
raise ValidationError(_("No purchase order found!"))
|
raise ValidationError(_("No purchase order found!"))
|
||||||
result['domain'] = [('id', 'in', po_ids)]
|
result['domain'] = [('id', 'in', po_ids)]
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
from odoo import api, fields, models, _
|
from odoo import api, fields, models, _
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.addons import decimal_precision as dp
|
||||||
|
|
||||||
|
|
||||||
class RmaOrderLine(models.Model):
|
class RmaOrderLine(models.Model):
|
||||||
@@ -11,29 +12,19 @@ class RmaOrderLine(models.Model):
|
|||||||
@api.multi
|
@api.multi
|
||||||
def _compute_purchase_count(self):
|
def _compute_purchase_count(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
purchase_list = []
|
rec.purchase_count = len(self.env['purchase.order'].search(
|
||||||
for procurement_id in rec.procurement_ids:
|
[('origin', 'ilike', rec.name)]).ids)
|
||||||
if procurement_id.purchase_id and \
|
|
||||||
procurement_id.purchase_id.id:
|
|
||||||
purchase_list.append(procurement_id.purchase_id.id)
|
|
||||||
rec.purchase_count = (
|
|
||||||
len(list(set(purchase_list))) +
|
|
||||||
len(rec.manual_purchase_line_ids.mapped('order_id')))
|
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def _compute_purchase_order_lines(self):
|
def _compute_purchase_order_lines(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
purchase_list = []
|
purchase_list = []
|
||||||
for purchase in self.env['purchase.order'].search(
|
for line in self.env['purchase.order.line'].search(
|
||||||
[('origin', 'ilike', rec.name)]):
|
[('rma_line_id', '=', rec.id)]):
|
||||||
for line in purchase.order_line:
|
|
||||||
purchase_list.append(line.id)
|
purchase_list.append(line.id)
|
||||||
rec.purchase_order_line_ids = [(6, 0, purchase_list)]
|
rec.purchase_order_line_ids = [(6, 0, purchase_list)]
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('procurement_ids.purchase_line_id',
|
|
||||||
'manual_purchase_line_ids',
|
|
||||||
'manual_purchase_line_ids.state', 'qty_delivered')
|
|
||||||
def _compute_qty_purchase(self):
|
def _compute_qty_purchase(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
rec.qty_purchased = rec._get_rma_purchased_qty()
|
rec.qty_purchased = rec._get_rma_purchased_qty()
|
||||||
@@ -78,12 +69,12 @@ class RmaOrderLine(models.Model):
|
|||||||
qty_to_purchase = fields.Float(
|
qty_to_purchase = fields.Float(
|
||||||
string='Qty To Purchase', copy=False,
|
string='Qty To Purchase', copy=False,
|
||||||
digits=dp.get_precision('Product Unit of Measure'),
|
digits=dp.get_precision('Product Unit of Measure'),
|
||||||
readonly=True, compute='_compute_qty_purchase', store=True,
|
readonly=True, compute='_compute_qty_purchase'
|
||||||
)
|
)
|
||||||
qty_purchased = fields.Float(
|
qty_purchased = fields.Float(
|
||||||
string='Qty Purchased', copy=False,
|
string='Qty Purchased', copy=False,
|
||||||
digits=dp.get_precision('Product Unit of Measure'),
|
digits=dp.get_precision('Product Unit of Measure'),
|
||||||
readonly=True, compute='_compute_qty_purchase', store=True,
|
readonly=True, compute='_compute_qty_purchase'
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.onchange('operation_id')
|
@api.onchange('operation_id')
|
||||||
@@ -176,8 +167,7 @@ class RmaOrderLine(models.Model):
|
|||||||
def action_view_purchase_order(self):
|
def action_view_purchase_order(self):
|
||||||
action = self.env.ref('purchase.purchase_rfq')
|
action = self.env.ref('purchase.purchase_rfq')
|
||||||
result = action.read()[0]
|
result = action.read()[0]
|
||||||
orders = self.mapped('procurement_ids.purchase_id')
|
orders = self.mapped('purchase_order_line_ids.order_id')
|
||||||
orders += self.mapped('manual_purchase_line_ids.order_id')
|
|
||||||
result['domain'] = [('id', 'in', orders.ids)]
|
result['domain'] = [('id', 'in', orders.ids)]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -187,13 +177,8 @@ class RmaOrderLine(models.Model):
|
|||||||
qty = 0.0
|
qty = 0.0
|
||||||
if self.type == 'customer':
|
if self.type == 'customer':
|
||||||
return qty
|
return qty
|
||||||
uom_obj = self.env['product.uom']
|
for line in self.purchase_order_line_ids.filtered(
|
||||||
for procurement_id in self.procurement_ids:
|
|
||||||
purchase_line = procurement_id.purchase_line_id
|
|
||||||
qty += purchase_line.product_qty
|
|
||||||
|
|
||||||
for line in self.manual_purchase_line_ids.filtered(
|
|
||||||
lambda p: p.state not in ('draft', 'sent', 'cancel')):
|
lambda p: p.state not in ('draft', 'sent', 'cancel')):
|
||||||
qty += uom_obj._compute_qty(
|
qty += self.uom_id._compute_quantity(
|
||||||
self.uom_id.id, line.product_qty, line.product_uom.id)
|
line.product_qty, line.product_uom)
|
||||||
return qty
|
return qty
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0"?>
|
||||||
<!-- Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
<!-- Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||||
<odoo>
|
<odoo>
|
||||||
|
|||||||
Reference in New Issue
Block a user