[ADD] new module crm_rma_prodlot_supplier

This commit is contained in:
Yanina Aular (Vauxoo)
2015-10-19 16:32:41 -04:30
parent feb1eda708
commit df07d7b3b6
15 changed files with 700 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright 2015 Vauxoo
# Author: Yanina Aular, Osval Reyes
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import stock_production_lot
from . import stock_transfer_details
from . import stock_picking

View File

@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright 2015 Vauxoo
# Author: Yanina Aular
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import api, models
class StockPicking(models.Model):
_inherit = 'stock.picking'
@api.multi
def action_invoice_create(self, journal_id,
group=False, type='out_invoice'):
invoices = super(StockPicking, self).\
action_invoice_create(journal_id=journal_id,
group=group,
type=type)
if type == 'in_invoice':
prodlot_obj = self.env['stock.production.lot']
for picking in self:
for move in picking.move_lines:
if move and move.quant_ids:
lot = move.quant_ids[0].lot_id
if lot.supplier_invoice_line_id:
continue
for inv_id in invoices:
for inv_line in self.env['account.invoice'].\
browse(inv_id).invoice_line:
lots = prodlot_obj.\
search([('supplier_invoice_line_id',
'=',
inv_line.id)])
if inv_line.product_id.id == \
lot.product_id.id and \
len(lots) < inv_line.quantity:
lot.write({'supplier_invoice_line_id':
inv_line.id})
return invoices

View File

@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright 2015 Vauxoo
# Author: Yanina Aular, Osval Reyes
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import api, fields, models
class StockProductionLot(models.Model):
_inherit = 'stock.production.lot'
supplier_id = fields.Many2one('res.partner', string='Supplier',
help="Supplier of good in claim")
supplier_invoice_line_id = \
fields.Many2one('account.invoice.line',
string='Supplier Invoice Line',
help="Supplier invoice with the "
"purchase of goods sold to "
"customer")
@api.model
def default_get(self, fields_list):
"""
Set partner when product lot is created
@param fields_list: record values
@return: return record
"""
res = super(StockProductionLot, self).default_get(fields_list)
prodlot_obj = self.env['stock.production.lot']
transfer_item_id = self._context.get('active_id', False)
if not transfer_item_id:
return res
picking = self.env['stock.transfer_details_items'].\
browse(transfer_item_id)
if picking.transfer_id.picking_id.picking_type_id.code != 'incoming':
return res
partner_id = picking.transfer_id.picking_id.partner_id
for move_line in picking.transfer_id.picking_id.move_lines:
if res.get('product_id') != move_line.product_id.id:
continue
lots = prodlot_obj.search([
('supplier_invoice_line_id',
'in', move_line.purchase_line_id.invoice_lines.mapped('id'))
])
if len(lots) < move_line.purchase_line_id.product_qty:
for inv_line in move_line.purchase_line_id.invoice_lines:
lots = prodlot_obj.\
search([('supplier_invoice_line_id',
'=', inv_line.id)])
if len(lots) < inv_line.quantity and \
inv_line.product_id.id == res.get('product_id'):
res.update({'supplier_invoice_line_id': inv_line.id})
if partner_id:
res.update({'supplier_id': partner_id.id})
return res

View File

@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright 2015 Vauxoo
# Author: Yanina Aular, Osval Reyes
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import api, models
class StockTransferDetails(models.TransientModel):
_inherit = 'stock.transfer_details'
@api.multi
def do_detailed_transfer(self):
"""
When incoming type transfer are made and stock move have serial/lot
number, the supplier is assigned to the serial/lot number taken from
picking.
@return: do_detailed_transfer boolean results
"""
prodlot = self.env['stock.production.lot']
if self.picking_id.picking_type_id.code != 'incoming':
return super(StockTransferDetails, self).do_detailed_transfer()
for items_packs_ids in [self.item_ids, self.packop_ids]:
for prod in items_packs_ids:
lot_id = prod.lot_id
if not lot_id:
continue
if not lot_id.supplier_id:
lot_id.write({
'supplier_id': self.picking_id.partner_id.id
})
for move_id in self.picking_id.move_lines:
if lot_id.product_id.id != move_id.product_id.id:
continue
lots = prodlot.search([
('supplier_invoice_line_id',
'in',
move_id.purchase_line_id.invoice_lines.mapped('id'))
])
if len(lots) < move_id.purchase_line_id.product_qty:
for inv_line in move_id.purchase_line_id.invoice_lines:
lots = prodlot.search([('supplier_invoice_line_id',
'=', inv_line.id)])
if len(lots) < inv_line.quantity and \
inv_line.product_id.id == \
lot_id.product_id.id:
lot_id.write({
'supplier_invoice_line_id': inv_line.id
})
return super(StockTransferDetails, self).do_detailed_transfer()