Refactory phytos
This commit is contained in:
parent
b287fa9eee
commit
05fb9c2c2b
|
@ -30,7 +30,8 @@ def register():
|
|||
quality.Phytosanitary,
|
||||
quality.ExportationPhyto,
|
||||
quality.ExportationPhytoLine,
|
||||
quality.PhytoMove,
|
||||
quality.PhytoStock,
|
||||
quality.PhytoStockMove,
|
||||
stock.StockMove,
|
||||
stock.ShipmentIn,
|
||||
stock.StockLot,
|
||||
|
|
39
quality.py
39
quality.py
|
@ -99,7 +99,7 @@ class Phytosanitary(ModelSQL, ModelView):
|
|||
__name__ = "farming.phyto"
|
||||
number = fields.Char('Number', required=True)
|
||||
party = fields.Many2One('party.party', 'Party', required=True)
|
||||
moves = fields.One2Many('farming.phyto.move', 'phyto', 'Moves')
|
||||
stocks = fields.One2Many('farming.phyto.stock', 'phyto', 'Stocks')
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
|
@ -117,20 +117,38 @@ class Phytosanitary(ModelSQL, ModelView):
|
|||
return '[' + self.number + '] ' + self.party.name
|
||||
|
||||
|
||||
class PhytoMove(ModelSQL, ModelView):
|
||||
"Phytosanitary Move"
|
||||
__name__ = "farming.phyto.move"
|
||||
number = fields.Char('Number', required=False)
|
||||
phyto = fields.Many2One('farming.phyto', 'Phyto')
|
||||
class PhytoStock(ModelSQL, ModelView):
|
||||
"Phytosanitary Stock"
|
||||
__name__ = "farming.phyto.stock"
|
||||
phyto = fields.Many2One('farming.phyto', 'Phyto', required=True,
|
||||
ondelete='CASCADE')
|
||||
lot = fields.Many2One('stock.lot', 'Lot')
|
||||
product = fields.Many2One('product.product', 'Product', required=True,
|
||||
domain=[('type', '=', 'goods')])
|
||||
balance = fields.Integer('Balance', states={'readonly': True})
|
||||
moves = fields.One2Many('farming.phyto.stock.move', 'stock', 'Moves')
|
||||
|
||||
@staticmethod
|
||||
def default_balance():
|
||||
return 0
|
||||
|
||||
|
||||
class PhytoStockMove(ModelSQL, ModelView):
|
||||
"Phytosanitary Stock Move"
|
||||
__name__ = "farming.phyto.stock.move"
|
||||
stock = fields.Many2One('farming.phyto.stock', 'Phyto', required=True,
|
||||
ondelete='CASCADE')
|
||||
date = fields.Date('Date', required=True)
|
||||
move_in = fields.Integer('Move In', required=True)
|
||||
move_out = fields.Integer('Move Out', required=True)
|
||||
balance = fields.Function(fields.Integer('Balance'), 'get_balance')
|
||||
move = fields.Many2One('stock.move', 'Move')
|
||||
move = fields.Many2One('stock.move', 'Move', required=True)
|
||||
|
||||
def get_balance(self, name):
|
||||
@staticmethod
|
||||
def default_move_in():
|
||||
return 0
|
||||
|
||||
@staticmethod
|
||||
def default_move_out():
|
||||
return 0
|
||||
|
||||
|
||||
|
@ -211,11 +229,12 @@ class ExportationPhyto(Workflow, ModelSQL, ModelView):
|
|||
def select_phytos(cls, records):
|
||||
pool = Pool()
|
||||
Sale = pool.get('sale.sale')
|
||||
Sale = pool.get('sale.sale')
|
||||
for charge in records:
|
||||
if not charge.carrier:
|
||||
continue
|
||||
|
||||
sales = Sale.search([
|
||||
sales = Phyto.search([
|
||||
('carrier', '=', charge.carrier.id),
|
||||
('state', '=', 'processing'),
|
||||
('charge', '=', None),
|
||||
|
|
25
quality.xml
25
quality.xml
|
@ -90,17 +90,30 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="name">product_species_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_phyto_move_view_tree">
|
||||
<field name="model">farming.phyto.move</field>
|
||||
<record model="ir.ui.view" id="farming_phyto_stock_view_tree">
|
||||
<field name="model">farming.phyto.stock</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority">10</field>
|
||||
<field name="name">phyto_move_tree</field>
|
||||
<field name="name">phyto_stock_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="farming_phyto_move_view_form">
|
||||
<field name="model">farming.phyto.move</field>
|
||||
<record model="ir.ui.view" id="farming_phyto_stock_view_form">
|
||||
<field name="model">farming.phyto.stock</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">phyto_move_form</field>
|
||||
<field name="name">phyto_stock_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_phyto_stock_move_view_tree">
|
||||
<field name="model">farming.phyto.stock.move</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="priority">10</field>
|
||||
<field name="name">phyto_stock_move_tree</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="farming_phyto_stock_move_view_form">
|
||||
<field name="model">farming.phyto.stock</field>
|
||||
<field name="type">form</field>
|
||||
<field name="name">phyto_stock_move_form</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="farming_phyto_view_tree">
|
||||
<field name="model">farming.phyto</field>
|
||||
<field name="type">tree</field>
|
||||
|
|
15
stock.py
15
stock.py
|
@ -57,21 +57,28 @@ class ShipmentIn(metaclass=PoolMeta):
|
|||
def done(cls, shipments):
|
||||
super(ShipmentIn, cls).done(shipments)
|
||||
Phyto = Pool().get('farming.phyto')
|
||||
to_add = []
|
||||
for ship in shipments:
|
||||
phyto = ship.phyto
|
||||
if not ship.phyto:
|
||||
continue
|
||||
|
||||
stocks = []
|
||||
for move in ship.incoming_moves:
|
||||
if not move.product.template.farming:
|
||||
continue
|
||||
|
||||
lot_id = cls.create_lot(ship.supplier, move.product, phyto)
|
||||
to_add.append({
|
||||
'product': move.product.id,
|
||||
st_move = {
|
||||
'date': move.effective_date,
|
||||
'move_in': move.quantity,
|
||||
'move_out': 0,
|
||||
'move': move.id,
|
||||
}
|
||||
stocks.append({
|
||||
'product': move.product.id,
|
||||
'lot': lot_id,
|
||||
'balance': move.quantity,
|
||||
'moves': [('create', [st_move])],
|
||||
})
|
||||
|
||||
Phyto.write([phyto], {'moves': [('create', to_add)]})
|
||||
Phyto.write([phyto], {'stocks': [('create', stocks)]})
|
||||
|
|
|
@ -6,5 +6,5 @@ this repository contains the full copyright notices and license terms. -->
|
|||
<field name="party"/>
|
||||
<label name="number"/>
|
||||
<field name="number"/>
|
||||
<field name="moves" colspan="4"/>
|
||||
<field name="stocks" colspan="4"/>
|
||||
</form>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="product"/>
|
||||
<field name="product"/>
|
||||
<label name="lot"/>
|
||||
<field name="lot"/>
|
||||
<label name="balance"/>
|
||||
<field name="balance"/>
|
||||
<field name="moves" colspan="4"/>
|
||||
</form>
|
|
@ -2,16 +2,12 @@
|
|||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<form>
|
||||
<label name="product"/>
|
||||
<field name="product"/>
|
||||
<label name="lot"/>
|
||||
<field name="lot"/>
|
||||
<label name="date"/>
|
||||
<field name="date"/>
|
||||
<label name="move"/>
|
||||
<field name="move"/>
|
||||
<label name="move_in"/>
|
||||
<field name="move_in"/>
|
||||
<label name="move_out"/>
|
||||
<field name="move_out"/>
|
||||
<label name="move"/>
|
||||
<field name="move"/>
|
||||
<label name="balance"/>
|
||||
<field name="balance"/>
|
||||
</form>
|
|
@ -2,10 +2,8 @@
|
|||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree>
|
||||
<field name="lot"/>
|
||||
<field name="product" expand="1"/>
|
||||
<field name="date" expand="1"/>
|
||||
<field name="move_in" expand="1"/>
|
||||
<field name="move_out" expand="1"/>
|
||||
<field name="balance" expand="1"/>
|
||||
<field name="move"/>
|
||||
<field name="move" expand="1"/>
|
||||
</tree>
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<tree>
|
||||
<field name="lot" expand="1"/>
|
||||
<field name="product" expand="1"/>
|
||||
<field name="balance" expand="1"/>
|
||||
</tree>
|
Loading…
Reference in New Issue