diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-01-08 05:28:28 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-01-08 05:28:28 +0000 |
| commit | d259006021bcbda554aa8fc78e6ab2dae20a3ac4 (patch) | |
| tree | f7c1b195347c02a532bc8e342aa640e74b62737c | |
| parent | 02d27a0e871dd4949c9382000843cd35dd3db3f8 (diff) | |
| parent | dfeb874b7b9d938b8c8863645d9b21830d1628dc (diff) | |
Merged in CR/SO-set-to-draft (pull request #259)
<iman> update code so reset to draft
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 19 | ||||
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 24 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 8 |
3 files changed, 47 insertions, 4 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index f5e7e8a1..7b2d9bf8 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1031,8 +1031,9 @@ class SaleOrder(models.Model): if self.have_outstanding_invoice: raise UserError("Invoice harus di Cancel dahulu") - elif self.have_outstanding_picking: - raise UserError("DO harus di Cancel dahulu") + for line in self.order_line: + if line.qty_delivered > 0: + raise UserError("DO harus di-cancel terlebih dahulu.") if not self.web_approval: self.web_approval = 'company' @@ -1410,4 +1411,16 @@ class SaleOrder(models.Model): 'npwp': partner.npwp, 'email': partner.email, 'customer_type': partner.customer_type, - })
\ No newline at end of file + }) + + def write(self, vals): + for order in self: + if order.state in ['sale', 'cancel']: + if 'order_line' in vals: + new_lines = vals.get('order_line', []) + for command in new_lines: + if command[0] == 0: # A new line is being added + raise UserError( + "SO tidak dapat ditambahkan produk baru karena SO sudah menjadi sale order.") + res = super(SaleOrder, self).write(vals) + return res
\ No newline at end of file diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index a31ff569..29a046fa 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -38,6 +38,14 @@ class SaleOrderLine(models.Model): md_vendor_id = fields.Many2one('res.partner', string='MD Vendor', readonly=True) margin_md = fields.Float(string='Margin MD') qty_free_bu = fields.Float(string='Free BU', compute='_get_qty_free_bandengan') + desc_updatable = fields.Boolean(string='desc boolean', default=False, compute='_get_desc_updatable') + + def _get_desc_updatable(self): + for line in self: + if line.product_id.id != 417724: + line.desc_updatable = False + else: + line.desc_updatable = True def _get_qty_free_bandengan(self): for line in self: @@ -272,6 +280,10 @@ class SaleOrderLine(models.Model): (line.product_id.short_spesification if line.product_id.short_spesification else '') line.name = line_name line.weight = line.product_id.weight + if line.product_id.id != 417724: + line.desc_updatable = False + else: + line.desc_updatable = True @api.constrains('vendor_id') def _check_vendor_id(self): @@ -378,4 +390,14 @@ class SaleOrderLine(models.Model): if not line.product_id.product_tmpl_id.sale_ok: raise UserError('Product %s belum bisa dijual, harap hubungi finance' % line.product_id.display_name) if not line.vendor_id or not line.purchase_price and not line.display_type == 'line_note': - raise UserError(_('Isi Vendor dan Harga Beli sebelum Request Approval'))
\ No newline at end of file + raise UserError(_('Isi Vendor dan Harga Beli sebelum Request Approval')) + + @api.depends('state') + def _compute_product_updatable(self): + for line in self: + if line.state == 'draft': + line.product_updatable = True + # line.desc_updatable = True + else: + line.product_updatable = False + # line.desc_updatable = False diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index 703b4d49..3539dbf3 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -107,6 +107,14 @@ {'readonly': [('state', 'in', ('done','cancel'))]} </attribute> </xpath> + <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree" position="inside"> + <field name="desc_updatable" invisible="1"/> + </xpath> + <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='name']" position="attributes"> + <attribute name="attrs"> + {'readonly': [('desc_updatable', '=', False)]} + </attribute> + </xpath> <xpath expr="//form/sheet/notebook/page/field[@name='order_line']/tree/field[@name='price_unit']" position="attributes"> <attribute name="attrs"> { |
