Advertisement
Guest User

Untitled

a guest
Dec 8th, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.65 KB | None | 0 0
  1. class PurchaseLine(metaclass=PoolMeta):
  2.     __name__ = 'purchase.line'
  3.  
  4.     blanket_agreement_line = fields.Many2One(
  5.         'purchase.blanket_agreement.line', "Purchase Blanket Agreement Line",
  6.         ondelete='RESTRICT',
  7.         domain=[
  8.             If(Eval('purchase_state').in_(['draft', 'quotation']), [
  9.                 ('agreement.state', 'in', ['done', 'cancelled', 'running']),
  10.                 ('product', '=', Eval('product'))],
  11.                 []),
  12.             ('agreement.supplier', '=',
  13.                 Eval('_parent_purchase', {}).get('party'),
  14.             ),
  15.         ],
  16.         depends=['product', 'purchase_state'])
  17.  
  18.     @fields.depends('blanket_agreement_line', '_parent_purchase.party',
  19.                     'purchase', methods=['compute_taxes'])
  20.     def on_change_blanket_agreement_line(self):
  21.         if self.blanket_agreement_line:
  22.             self.product = self.blanket_agreement_line.product
  23.             if not self.description:
  24.                 self.description = self.blanket_agreement_line.description
  25.             self.unit = self.blanket_agreement_line.unit
  26.             if not self.unit_price:
  27.                 self.unit_price = self.blanket_agreement_line.unit_price
  28.             if not self.quantity:
  29.                 self.quantity = self.blanket_agreement_line.remaining_quantity
  30.             self.taxes = self.compute_taxes(self.purchase.party)
  31.  
  32.     @fields.depends('blanket_agreement_line', 'product')
  33.     def on_change_product(self):
  34.         super().on_change_product()
  35.         if self.blanket_agreement_line:
  36.             if self.product != self.blanket_agreement_line.product:
  37.                 self.blanket_agreement_line = None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement