Browse Source

better way ok for bills

pull/134/head
devCbssolutionsRo 6 years ago
parent
commit
2677f010ef
  1. 87
      invoice_stock_move/models/invoice_stock.py
  2. 12
      invoice_stock_move/views/invoice_stock_move_view.xml

87
invoice_stock_move/models/invoice_stock.py

@ -21,67 +21,55 @@
#############################################################################
from odoo.exceptions import UserError
from odoo import models, fields, api, _
#from odoo.doc._extensions.pyjsparser.parser import false
class InvoiceStockMove(models.Model):
_inherit = 'account.move'
@api.onchange('type')
@api.onchange('type','invoice_line_ids')
def onchange_invoice_type(self):
if self.type in ['out_invoice','out_receipt']:
domain="[('code','=','incoming')]"
else:
domain="[('code','=','outgoing')]"
transfer_state = 'nothing_to_transfer'
for line in self.invoice_line_ids:
if line.product_id:
if line.product_id.type == 'product':
transfer_state = 'not_done'
break
self.transfer_state = transfer_state
domain=[('id','=',0)]
if transfer_state == 'not_done':
if self.type in ['out_invoice','out_receipt']:
domain=[('code','=','outgoing')]
elif self.type in ['in_invoice','in_receipt']:
domain=[('code','=','incoming')]
if not self.picking_type_id:
type_obj = self.env['stock.picking.type']
company_id = self.env.context.get('company_id') or self.env.user.company_id.id
full_domain = domain+ [('warehouse_id.company_id', '=', company_id)]
self.picking_type_id = type_obj.search(full_domain, limit=1)
# types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)])
return {'domain': {'picking_type_id': domain}}
@api.model
def _default_picking_receive(self):
type_obj = self.env['stock.picking.type']
company_id = self.env.context.get('company_id') or self.env.user.company_id.id
types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)], limit=1)
if not types:
types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)])
return types[:1]
@api.model
def _default_picking_transfer(self):
type_obj = self.env['stock.picking.type']
company_id = self.env.context.get('company_id') or self.env.user.company_id.id
types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id.company_id', '=', company_id)], limit=1)
if not types:
types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id', '=', False)])
return types[:4]
picking_count = fields.Integer(string="Count",copy=False)
transfer_state = fields.Selection([('not_done','not_done'),('nothing_to_transfer','nothing_to_transfer'),('done','done')],help='If the tranfer form invoice was done or not')
invoice_picking_id = fields.Many2one('stock.picking', string="Picking Id",copy=False)
picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', required=True,
default=_default_picking_receive,
picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', required=False,
help="This will determine picking type of incoming shipment",copy=False)
picking_transfer_id = fields.Many2one('stock.picking.type', 'Deliver To', required=True,
default=_default_picking_transfer,
help="This will determine picking type of outgoing shipment",copy=False)
state = fields.Selection([
('draft', 'Draft'),
('proforma', 'Pro-forma'),
('proforma2', 'Pro-forma'),
('posted', 'Posted'),
('post', 'Post'),
('cancel', 'Cancelled'),
('done', 'Received'),
], string='Status', index=True, readonly=True, default='draft',
track_visibility='onchange', copy=False)
# picking_transfer_id = fields.Many2one('stock.picking.type', 'Deliver To', required=True,
# help="This will determine picking type of outgoing shipment",copy=False)
# state = fields.Selection([
# ('draft', 'Draft'),
# ('proforma', 'Pro-forma'),
# ('proforma2', 'Pro-forma'),
# ('posted', 'Posted'),
# ('post', 'Post'),
# ('cancel', 'Cancelled'),
# ('done', 'Received'),
# ], string='Status', index=True, readonly=True, default='draft',
# track_visibility='onchange', copy=False)
def action_stock_move(self):
"will be executed at the pressing of transfer button"
for order in self: # order is account.move meaning also invoice
exist_stockable_products = False
for line in order.invoice_line_ids:
if line.product_id:
if line.product_id.type == 'product':
exist_stockable_products = True
break
if exist_stockable_products and not self.invoice_picking_id:
if not self.invoice_picking_id:
pick = {
'picking_type_id': self.picking_type_id.id,
'partner_id': self.partner_id.id,
@ -91,14 +79,11 @@ class InvoiceStockMove(models.Model):
}
picking = self.env['stock.picking'].create(pick)
self.invoice_picking_id = picking.id
self.picking_count = len(picking)
self.transfer_state = 'done'
moves = order.invoice_line_ids.filtered(lambda r: r.product_id.type in ['product'])._create_stock_moves(picking)
#, 'consu'
move_ids = moves._action_confirm()
move_ids._action_assign()
else:
self.invoice_picking_id = false
self.picking_count = 0
def action_view_picking(self):
action = self.env.ref('stock.action_picking_tree_ready')

12
invoice_stock_move/views/invoice_stock_move_view.xml

@ -8,20 +8,20 @@
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button name="action_stock_move" string="Transfer" type="object" class="oe_highlight"
attrs="{'invisible':['|',('state', '=', 'draft'),('picking_count', '=', 0)]}"/>
attrs="{'invisible':['|',('state', '=', 'draft'),('transfer_state', '!=', 'not_done')]}"/>
</xpath>
<xpath expr="//field[@name='invoice_date']" position="after">
<field name="picking_type_id" />
<field name="invoice_picking_id" invisible="0" readonly="1" force_save="1"/>
<field name="picking_type_id" attrs="{'invisible':[('transfer_state','=','nothing_to_transfer')],'readonly':[('state','not in',['draft'])]}"/>
<field name="transfer_state" invisible="1"/>
</xpath>
<xpath expr="//field[@name='name']" position="before">
<div class="oe_button_box" name="button_box">
<button type="object"
name="action_view_picking" states="open,paid"
class="oe_stat_button" attrs="{'invisible':['|',('state','=','draft'),('picking_count', '&lt;', 1)]}"
class="oe_stat_button" attrs="{'invisible':['|',('state','=','draft'),('transfer_state', '!=', 'done')]}"
icon="fa-truck">
<field name="picking_count" string="Shipment" widget="statinfo"/>
</button>
<!-- <field name="transfer_state" string="Shipment" widget="statinfo"/>
--> </button>
</div>
</xpath>
</field>

Loading…
Cancel
Save