Esempio n. 1
0
    def _get_consignment_expense_partner(self):
        owner = self.move_line_ids.mapped("owner_id")

        if not owner:
            supplier_info = get_supplier_info_from_product(self.product_id)
            owner = supplier_info.mapped("name.commercial_partner_id")

        return owner[0]
Esempio n. 2
0
 def _check_single_consignment_vendor(self):
     supplier_info = get_supplier_info_from_product(self)
     vendors = supplier_info.mapped('name.commercial_partner_id')
     if len(vendors) > 1:
         raise ValidationError(
             _('The product {product} is consigned. '
               'Therefore, you may not select more than one different vendor '
               'on this product. The following vendors were selected:\n'
               ' * {vendors}').format(product=self.display_name,
                                      vendors='\n * '.join(
                                          vendors.mapped('display_name'))))
Esempio n. 3
0
    def _check_product_sellers(self):
        expected_supplier = self.partner_id.commercial_partner_id

        for line in self.order_line:
            supplier_info = get_supplier_info_from_product(line.product_id)
            authorized_suppliers = supplier_info.mapped(
                'name.commercial_partner_id')

            if expected_supplier not in authorized_suppliers:
                raise exceptions.ValidationError(
                    _("The product {product} is not allowed for the supplier {supplier}.\n"
                      "Please contact your manager.").format(
                          product=line.product_id.display_name,
                          supplier=expected_supplier.display_name,
                      ))
Esempio n. 4
0
 def _check_single_consignment_vendor(self):
     supplier_info = get_supplier_info_from_product(self)
     vendors = supplier_info.mapped("name.commercial_partner_id")
     if len(vendors) > 1:
         raise ValidationError(
             _(
                 "The product {product} is consigned. "
                 "Therefore, you may not select more than one different vendor "
                 "on this product. The following vendors were selected:\n"
                 " * {vendors}"
             ).format(
                 product=self.display_name,
                 vendors="\n * ".join(vendors.mapped("display_name")),
             )
         )
    def _check_product_consignment_vendor(self):
        """Check that the vendor defined on product is the vendor on the PO.

        The commercial partner must be defined in the list of prices for the product.
        """
        supplier_info = get_supplier_info_from_product(self.product_id)
        vendors_on_product = supplier_info.mapped('name.commercial_partner_id')
        vendor_on_po = self.order_id.partner_id.commercial_partner_id

        if vendor_on_po not in vendors_on_product:
            raise ValidationError(
                _('The purchase order {order} can not be confirmed because '
                  'the supplier {supplier} defined on the PO is absent from '
                  'the list of suppliers for the consigned product {product}.'
                  ).format(
                      order=self.order_id.display_name,
                      supplier=vendor_on_po.display_name,
                      product=self.product_id.display_name,
                  ))
 def _get_commercial_suppliers(self):
     supplier_info = get_supplier_info_from_product(self)
     return supplier_info.mapped("name.commercial_partner_id")
Esempio n. 7
0
 def __get_main_supplier_info(self):
     company_id = self.__get_company_id()
     supplier_info = (get_supplier_info_from_product(self).sorted(
         key=lambda s: (0 if s.product_id else 1, s.sequence)).filtered(
             lambda s: not s.company_id or s.company_id.id == company_id))
     return supplier_info[:1]