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.
|
||||
# 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):
|
||||
@@ -24,6 +23,4 @@ class PurchaseOrder(models.Model):
|
||||
'product_uom': rma_line.uom_id.id,
|
||||
})
|
||||
res.order_line = line
|
||||
# TODO: maybe this line is not needed in v10:
|
||||
res.date_planned = res._compute_date_planned()
|
||||
return res
|
||||
|
||||
@@ -1,16 +1,12 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
|
||||
# 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):
|
||||
_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(
|
||||
comodel_name='rma.order.line', string='RMA',
|
||||
)
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
|
||||
|
||||
from openerp import api, fields, models, _
|
||||
from openerp.exceptions import ValidationError
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class RmaOperation(models.Model):
|
||||
|
||||
@@ -12,9 +12,12 @@ class RmaOrder(models.Model):
|
||||
def _compute_po_count(self):
|
||||
for rec in self:
|
||||
po_count = 0
|
||||
rma_line_po = []
|
||||
for line in rec.rma_line_ids:
|
||||
po_count += len(self.env['purchase.order'].search(
|
||||
[('origin', '=', line.name)]).ids)
|
||||
rma_line_po += self.env['purchase.order'].search(
|
||||
[('origin', '=', line.name)]).ids
|
||||
if rma_line_po:
|
||||
po_count = len(list(set(rma_line_po)))
|
||||
rec.po_count = po_count
|
||||
|
||||
@api.multi
|
||||
@@ -35,6 +38,9 @@ class RmaOrder(models.Model):
|
||||
result = action.read()[0]
|
||||
po_ids = self.env['purchase.order'].search(
|
||||
[('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:
|
||||
raise ValidationError(_("No purchase order found!"))
|
||||
result['domain'] = [('id', 'in', po_ids)]
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.addons import decimal_precision as dp
|
||||
|
||||
|
||||
class RmaOrderLine(models.Model):
|
||||
@@ -11,29 +12,19 @@ class RmaOrderLine(models.Model):
|
||||
@api.multi
|
||||
def _compute_purchase_count(self):
|
||||
for rec in self:
|
||||
purchase_list = []
|
||||
for procurement_id in rec.procurement_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')))
|
||||
rec.purchase_count = len(self.env['purchase.order'].search(
|
||||
[('origin', 'ilike', rec.name)]).ids)
|
||||
|
||||
@api.multi
|
||||
def _compute_purchase_order_lines(self):
|
||||
for rec in self:
|
||||
purchase_list = []
|
||||
for purchase in self.env['purchase.order'].search(
|
||||
[('origin', 'ilike', rec.name)]):
|
||||
for line in purchase.order_line:
|
||||
purchase_list.append(line.id)
|
||||
for line in self.env['purchase.order.line'].search(
|
||||
[('rma_line_id', '=', rec.id)]):
|
||||
purchase_list.append(line.id)
|
||||
rec.purchase_order_line_ids = [(6, 0, purchase_list)]
|
||||
|
||||
@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):
|
||||
for rec in self:
|
||||
rec.qty_purchased = rec._get_rma_purchased_qty()
|
||||
@@ -78,12 +69,12 @@ class RmaOrderLine(models.Model):
|
||||
qty_to_purchase = fields.Float(
|
||||
string='Qty To Purchase', copy=False,
|
||||
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(
|
||||
string='Qty Purchased', copy=False,
|
||||
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')
|
||||
@@ -176,8 +167,7 @@ class RmaOrderLine(models.Model):
|
||||
def action_view_purchase_order(self):
|
||||
action = self.env.ref('purchase.purchase_rfq')
|
||||
result = action.read()[0]
|
||||
orders = self.mapped('procurement_ids.purchase_id')
|
||||
orders += self.mapped('manual_purchase_line_ids.order_id')
|
||||
orders = self.mapped('purchase_order_line_ids.order_id')
|
||||
result['domain'] = [('id', 'in', orders.ids)]
|
||||
return result
|
||||
|
||||
@@ -187,13 +177,8 @@ class RmaOrderLine(models.Model):
|
||||
qty = 0.0
|
||||
if self.type == 'customer':
|
||||
return qty
|
||||
uom_obj = self.env['product.uom']
|
||||
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(
|
||||
for line in self.purchase_order_line_ids.filtered(
|
||||
lambda p: p.state not in ('draft', 'sent', 'cancel')):
|
||||
qty += uom_obj._compute_qty(
|
||||
self.uom_id.id, line.product_qty, line.product_uom.id)
|
||||
qty += self.uom_id._compute_quantity(
|
||||
line.product_qty, line.product_uom)
|
||||
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.
|
||||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
|
||||
<odoo>
|
||||
|
||||
Reference in New Issue
Block a user