-
Notifications
You must be signed in to change notification settings - Fork 2
/
models_mrp_unbuild.go
executable file
·257 lines (250 loc) · 9.43 KB
/
models_mrp_unbuild.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
package mrp
import (
"net/http"
"github.com/hexya-erp/hexya/src/controllers"
"github.com/hexya-erp/hexya/src/models"
"github.com/hexya-erp/hexya/src/models/types"
"github.com/hexya-erp/hexya/src/models/types/dates"
"github.com/hexya-erp/pool/h"
"github.com/hexya-erp/pool/q"
)
func init() {
h.MrpUnbuild().DeclareModel()
h.MrpUnbuild().Methods().GetDefaultLocationId().DeclareMethod(
`GetDefaultLocationId`,
func(rs m.MrpUnbuildSet) {
// return self.env.ref('stock.stock_location_stock', raise_if_not_found=False)
})
h.MrpUnbuild().Methods().GetDefaultLocationDestId().DeclareMethod(
`GetDefaultLocationDestId`,
func(rs m.MrpUnbuildSet) {
// return self.env.ref('stock.stock_location_stock', raise_if_not_found=False)
})
h.MrpUnbuild().AddFields(map[string]models.FieldDefinition{
"Name": models.CharField{
String: "Reference",
NoCopy: true,
ReadOnly: true,
Default: func (env models.Environment) interface{} { return odoo._() },
},
"ProductId": models.Many2OneField{
RelationModel: h.ProductProduct(),
String: "Product",
Required: true,
//states={'done': [('readonly', True)]}
},
"ProductQty": models.FloatField{
String: "Quantity",
Required: true,
//states={'done': [('readonly', True)]}
},
"ProductUomId": models.Many2OneField{
RelationModel: h.ProductUom(),
String: "Unit of Measure",
Required: true,
//states={'done': [('readonly', True)]}
},
"BomId": models.Many2OneField{
RelationModel: h.MrpBom(),
String: "Bill of Material",
Filter: q.ProductTmplId().Equals("product_id.product_tmpl_id"),
Required: true,
//states={'done': [('readonly', True)]}
},
"MoId": models.Many2OneField{
RelationModel: h.MrpProduction(),
String: "Manufacturing Order",
Filter: q.ProductId().Equals(product_id).And().State().In(%!s(<nil>)),
//states={'done': [('readonly', True)]}
},
"LotId": models.Many2OneField{
RelationModel: h.StockProductionLot(),
String: "Lot",
Filter: q.ProductId().Equals(product_id),
//states={'done': [('readonly', True)]}
},
"HasTracking": models.SelectionField{
Related: `ProductId.Tracking`,
ReadOnly: true,
},
"LocationId": models.Many2OneField{
RelationModel: h.StockLocation(),
String: "Location",
Default: models.DefaultValue(_get_default_location_id),
Required: true,
//states={'done': [('readonly', True)]}
},
"LocationDestId": models.Many2OneField{
RelationModel: h.StockLocation(),
String: "Destination Location",
Default: models.DefaultValue(_get_default_location_dest_id),
Required: true,
//states={'done': [('readonly', True)]}
},
"ConsumeLineIds": models.One2ManyField{
RelationModel: h.StockMove(),
ReverseFK: "",
ReadOnly: true,
Help: "",
},
"ProduceLineIds": models.One2ManyField{
RelationModel: h.StockMove(),
ReverseFK: "",
ReadOnly: true,
Help: "",
},
"State": models.SelectionField{
Selection: types.Selection{
"draft": "Draft",
"done": "Done",
},
String: "Status",
Default: models.DefaultValue("draft"),
Index: true,
},
})
h.MrpUnbuild().Methods().OnchangeMoId().DeclareMethod(
`OnchangeMoId`,
func(rs m.MrpUnbuildSet) {
// if self.mo_id:
// self.product_id = self.mo_id.product_id.id
// self.product_qty = self.mo_id.product_qty
})
h.MrpUnbuild().Methods().OnchangeProductId().DeclareMethod(
`OnchangeProductId`,
func(rs m.MrpUnbuildSet) {
// if self.product_id:
// self.bom_id = self.env['mrp.bom']._bom_find(
// product=self.product_id)
// self.product_uom_id = self.product_id.uom_id.id
})
h.MrpUnbuild().Methods().CheckQty().DeclareMethod(
`CheckQty`,
func(rs m.MrpUnbuildSet) {
// if self.product_qty <= 0:
// raise ValueError(
// _('Unbuild Order product quantity has to be strictly positive.'))
})
h.MrpUnbuild().Methods().Create().Extend(
`Create`,
func(rs m.MrpUnbuildSet, vals models.RecordData) {
// if not vals.get('name'):
// vals['name'] = self.env['ir.sequence'].next_by_code(
// 'mrp.unbuild') or _('New')
// unbuild = super(MrpUnbuild, self).create(vals)
// return unbuild
})
h.MrpUnbuild().Methods().ActionUnbuild().DeclareMethod(
`ActionUnbuild`,
func(rs m.MrpUnbuildSet) {
// self.ensure_one()
// if self.product_id.tracking != 'none' and not self.lot_id.id:
// raise UserError(_('Should have a lot for the finished product'))
// consume_move = self._generate_consume_moves()[0]
// produce_moves = self._generate_produce_moves()
// qty = self.product_qty # Convert to qty on product UoM
// if self.mo_id:
// finished_moves = self.mo_id.move_finished_ids.filtered(
// lambda move: move.product_id == self.mo_id.product_id)
// domain = [('qty', '>', 0), ('history_ids',
// 'in', finished_moves.ids)]
// else:
// domain = [('qty', '>', 0)]
// quants = self.env['stock.quant'].quants_get_preferred_domain(
// qty, consume_move,
// domain=domain,
// preferred_domain_list=[],
// lot_id=self.lot_id.id)
// self.env['stock.quant'].quants_reserve(quants, consume_move)
// if consume_move.has_tracking != 'none':
// if not quants[0][0]:
// raise UserError(
// _("You don't have in the stock the lot %s.") % (self.lot_id.name))
// self.env['stock.move.lots'].create({
// 'move_id': consume_move.id,
// 'lot_id': self.lot_id.id,
// 'quantity_done': consume_move.product_uom_qty,
// 'quantity': consume_move.product_uom_qty})
// else:
// consume_move.quantity_done = consume_move.product_uom_qty
// consume_move.move_validate()
// original_quants = consume_move.quant_ids.mapped('consumed_quant_ids')
// for produce_move in produce_moves:
// if produce_move.has_tracking != 'none':
// original = original_quants.filtered(
// lambda quant: quant.product_id == produce_move.product_id)
// if not original:
// raise UserError(
// _("You don't have in the stock the required lot/serial number for %s .") % (produce_move.product_id.name))
// quantity_todo = produce_move.product_qty
// for quant in original:
// if quantity_todo <= 0:
// break
// move_quantity = min(quantity_todo, quant.qty)
// self.env['stock.move.lots'].create({
// 'move_id': produce_move.id,
// 'lot_id': quant.lot_id.id,
// 'quantity_done': produce_move.product_id.uom_id._compute_quantity(move_quantity, produce_move.product_uom),
// 'quantity': produce_move.product_id.uom_id._compute_quantity(move_quantity, produce_move.product_uom),
// })
// quantity_todo -= move_quantity
// else:
// produce_move.quantity_done = produce_move.product_uom_qty
// produce_moves.move_validate()
// produced_quant_ids = produce_moves.mapped(
// 'quant_ids').filtered(lambda quant: quant.qty > 0)
// consume_move.quant_ids.sudo().write(
// {'produced_quant_ids': [(6, 0, produced_quant_ids.ids)]})
// return self.write({'state': 'done'})
})
h.MrpUnbuild().Methods().GenerateConsumeMoves().DeclareMethod(
`GenerateConsumeMoves`,
func(rs m.MrpUnbuildSet) {
// moves = self.env['stock.move']
// for unbuild in self:
// move = self.env['stock.move'].create({
// 'name': unbuild.name,
// 'date': unbuild.create_date,
// 'product_id': unbuild.product_id.id,
// 'product_uom': unbuild.product_uom_id.id,
// 'product_uom_qty': unbuild.product_qty,
// 'location_id': unbuild.location_id.id,
// 'location_dest_id': unbuild.product_id.property_stock_production.id,
// 'origin': unbuild.name,
// 'consume_unbuild_id': unbuild.id,
// })
// move.action_confirm()
// moves += move
// return moves
})
h.MrpUnbuild().Methods().GenerateProduceMoves().DeclareMethod(
`GenerateProduceMoves`,
func(rs m.MrpUnbuildSet) {
// moves = self.env['stock.move']
// for unbuild in self:
// factor = unbuild.product_uom_id._compute_quantity(
// unbuild.product_qty, unbuild.bom_id.product_uom_id) / unbuild.bom_id.product_qty
// boms, lines = unbuild.bom_id.explode(
// unbuild.product_id, factor, picking_type=unbuild.bom_id.picking_type_id)
// for line, line_data in lines:
// moves += unbuild._generate_move_from_bom_line(
// line, line_data['qty'])
// return moves
})
h.MrpUnbuild().Methods().GenerateMoveFromBomLine().DeclareMethod(
`GenerateMoveFromBomLine`,
func(rs m.MrpUnbuildSet, bom_line interface{}, quantity interface{}) {
// return self.env['stock.move'].create({
// 'name': self.name,
// 'date': self.create_date,
// 'bom_line_id': bom_line.id,
// 'product_id': bom_line.product_id.id,
// 'product_uom_qty': quantity,
// 'product_uom': bom_line.product_uom_id.id,
// 'procure_method': 'make_to_stock',
// 'location_dest_id': self.location_dest_id.id,
// 'location_id': self.product_id.property_stock_production.id,
// 'unbuild_id': self.id,
// })
})
}