mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[IMP] code
This commit is contained in:
committed by
Chanakya Soni
parent
e0647a7381
commit
bd8da45abe
@@ -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):
|
||||||
@@ -20,10 +19,8 @@ class PurchaseOrder(models.Model):
|
|||||||
})
|
})
|
||||||
line.onchange_product_id()
|
line.onchange_product_id()
|
||||||
line.update({
|
line.update({
|
||||||
'product_qty': rma_line.qty_to_purchase,
|
'product_qty': rma_line.product_qty,
|
||||||
'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',
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,14 +11,8 @@ 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):
|
||||||
@@ -30,20 +24,6 @@ class RmaOrderLine(models.Model):
|
|||||||
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.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()
|
|
||||||
if rec.purchase_policy == 'ordered':
|
|
||||||
rec.qty_to_purchase = rec.product_qty - rec.qty_purchased
|
|
||||||
elif rec.purchase_policy == 'delivered':
|
|
||||||
rec.qty_to_purchase = rec.qty_delivered - rec.qty_purchased
|
|
||||||
else:
|
|
||||||
rec.qty_to_purchase = 0.0
|
|
||||||
|
|
||||||
purchase_count = fields.Integer(
|
purchase_count = fields.Integer(
|
||||||
compute='_compute_purchase_count', string='# of Purchases',
|
compute='_compute_purchase_count', string='# of Purchases',
|
||||||
)
|
)
|
||||||
@@ -75,16 +55,6 @@ class RmaOrderLine(models.Model):
|
|||||||
inverse_name='rma_line_id',
|
inverse_name='rma_line_id',
|
||||||
string='Manual Purchase Order Lines',
|
string='Manual Purchase Order Lines',
|
||||||
readonly=True, copy=False)
|
readonly=True, copy=False)
|
||||||
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,
|
|
||||||
)
|
|
||||||
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,
|
|
||||||
)
|
|
||||||
|
|
||||||
@api.onchange('operation_id')
|
@api.onchange('operation_id')
|
||||||
def _onchange_operation_id(self):
|
def _onchange_operation_id(self):
|
||||||
@@ -180,20 +150,3 @@ class RmaOrderLine(models.Model):
|
|||||||
orders += self.mapped('manual_purchase_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
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def _get_rma_purchased_qty(self):
|
|
||||||
self.ensure_one()
|
|
||||||
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(
|
|
||||||
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)
|
|
||||||
return qty
|
|
||||||
|
|||||||
@@ -35,12 +35,6 @@
|
|||||||
('order_id.partner_id', '=', partner_id),
|
('order_id.partner_id', '=', partner_id),
|
||||||
('order_id.partner_id', 'child_of', partner_id)]"/>
|
('order_id.partner_id', 'child_of', partner_id)]"/>
|
||||||
</group>
|
</group>
|
||||||
<group name="quantities" position="inside">
|
|
||||||
<group>
|
|
||||||
<field name="qty_to_purchase"/>
|
|
||||||
<field name="qty_purchased"/>
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
<field name="delivery_policy" position="after">
|
<field name="delivery_policy" position="after">
|
||||||
<field name="purchase_policy"/>
|
<field name="purchase_policy"/>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user